From 3a2bd267a67d41a461946a6f7b0a99262f47d8a7 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Mon, 23 Oct 2017 11:38:56 +0200 Subject: Refactor grid shift functions. This refactoring of the grid shift functions allows for easier access to the actual grid values, as well as making it possible to perform horizontal grid shift on a single coordinate without using the pj_apply_gridshift* functions. The latter simplifies the execution path of the forward and inverse functions in PJ_hgridshift.c. This commit introduces proj_*grid_init, proj_*grid_value and proj_hgrid_apply. The init functions initialises horizontal and vertical grids respectivelive (wrappers for pj_gridlist_from_nadgrids with simpler parameters). The proj_*grid_value functions returns the specific grid value at coordinate lp. The proj_hgrid_apply function applies the grid offset to the input coordinate and outputs the adjusted coordinate. --- src/PJ_vgridshift.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'src/PJ_vgridshift.c') diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c index ededd544..691f791b 100644 --- a/src/PJ_vgridshift.c +++ b/src/PJ_vgridshift.c @@ -9,14 +9,10 @@ static XYZ forward_3d(LPZ lpz, PJ *P) { PJ_TRIPLET point; point.lpz = lpz; - if (P->gridlist != NULL) { + if (P->vgridlist_geoid != NULL) { /* Only try the gridshift if at least one grid is loaded, * otherwise just pass the coordinate through unchanged. */ - pj_apply_vgridshift( P, "sgrids", - &(P->gridlist), - &(P->gridlist_count), - 1, 1, 0, - &point.xyz.x, &point.xyz.y, &point.xyz.z ); + point.xyz.z -= proj_vgrid_value(P, point.lp); } return point.xyz; @@ -27,14 +23,10 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) { PJ_TRIPLET point; point.xyz = xyz; - if (P->gridlist != NULL) { + if (P->vgridlist_geoid != NULL) { /* Only try the gridshift if at least one grid is loaded, * otherwise just pass the coordinate through unchanged. */ - pj_apply_vgridshift( P, "sgrids", - &(P->gridlist), - &(P->gridlist_count), - 0, 1, 0, - &point.xyz.x, &point.xyz.y, &point.xyz.z ); + point.xyz.z += proj_vgrid_value(P, point.lp); } return point.lpz; @@ -61,14 +53,13 @@ PJ *PROJECTION(vgridshift) { return pj_default_destructor(P, PJD_ERR_NO_ARGS); } - /* Build gridlist. P->gridlist can be empty if +grids only ask for optional grids. */ - P->gridlist = pj_gridlist_from_nadgrids( P->ctx, pj_param(P->ctx, P->params, "sgrids").s, - &(P->gridlist_count) ); + /* Build gridlist. P->vgridlist_geoid can be empty if +grids only ask for optional grids. */ + proj_vgrid_init(P, "grids"); /* Was gridlist compiled properly? */ - if ( pj_ctx_get_errno(P->ctx) ) { + if ( proj_errno(P) ) { proj_log_error(P, "vgridshift: could not find required grid(s)."); - return pj_default_destructor(P, -38); + return pj_default_destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID); } P->fwdobs = forward_obs; -- cgit v1.2.3 From 8eb82852f5f7d23994839ba5d032edc76eab2250 Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Mon, 6 Nov 2017 10:02:05 +0100 Subject: Eliminate the last traces of PJ_OBS (#643) PJ_OBS eliminated, API adjusted to reflect that we now have only one 4D data type. 2 new API functions added to determine output types of a PJ. --- src/PJ_vgridshift.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/PJ_vgridshift.c') diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c index 691f791b..9db0b332 100644 --- a/src/PJ_vgridshift.c +++ b/src/PJ_vgridshift.c @@ -33,15 +33,15 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) { } -static PJ_OBS forward_obs(PJ_OBS obs, PJ *P) { - PJ_OBS point; - point.coo.xyz = forward_3d (obs.coo.lpz, P); +static PJ_COORD forward_4d(PJ_COORD obs, PJ *P) { + PJ_COORD point; + point.xyz = forward_3d (obs.lpz, P); return point; } -static PJ_OBS reverse_obs(PJ_OBS obs, PJ *P) { - PJ_OBS point; - point.coo.lpz = reverse_3d (obs.coo.xyz, P); +static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) { + PJ_COORD point; + point.lpz = reverse_3d (obs.xyz, P); return point; } @@ -62,8 +62,8 @@ PJ *PROJECTION(vgridshift) { return pj_default_destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID); } - P->fwdobs = forward_obs; - P->invobs = reverse_obs; + P->fwd4d = forward_4d; + P->inv4d = reverse_4d; P->fwd3d = forward_3d; P->inv3d = reverse_3d; P->fwd = 0; @@ -82,7 +82,7 @@ int pj_vgridshift_selftest (void) {return 0;} #else int pj_vgridshift_selftest (void) { PJ *P; - PJ_OBS expect, a, b; + PJ_COORD expect, a, b; double dist; int failures = 0; @@ -105,29 +105,29 @@ int pj_vgridshift_selftest (void) { if (0==P) return 10; - a = proj_obs_null; - a.coo.lpz.lam = PJ_TORAD(12.5); - a.coo.lpz.phi = PJ_TORAD(55.5); + a = proj_coord(0,0,0,0); + a.lpz.lam = PJ_TORAD(12.5); + a.lpz.phi = PJ_TORAD(55.5); - dist = proj_roundtrip (P, PJ_FWD, 1, a.coo); + dist = proj_roundtrip (P, PJ_FWD, 1, a); if (dist > 0.00000001) return 1; expect = a; /* Appears there is a difference between the egm96_15.gtx distributed by OSGeo4W, */ /* and the one from http://download.osgeo.org/proj/vdatum/egm96_15/egm96_15.gtx */ - /* Was: expect.coo.lpz.z = -36.021305084228515625; (download.osgeo.org) */ - /* Was: expect.coo.lpz.z = -35.880001068115234000; (OSGeo4W) */ + /* Was: expect.lpz.z = -36.021305084228515625; (download.osgeo.org) */ + /* Was: expect.lpz.z = -35.880001068115234000; (OSGeo4W) */ /* This is annoying, but must be handled elsewhere. So for now, we check for both. */ - expect.coo.lpz.z = -36.021305084228516; + expect.lpz.z = -36.021305084228516; failures = 0; - b = proj_trans_obs(P, PJ_FWD, a); - if (proj_xyz_dist(expect.coo.xyz, b.coo.xyz) > 1e-4) failures++; - expect.coo.lpz.z = -35.880001068115234000; - if (proj_xyz_dist(expect.coo.xyz, b.coo.xyz) > 1e-4) failures++; + b = proj_trans(P, PJ_FWD, a); + if (proj_xyz_dist(expect.xyz, b.xyz) > 1e-4) failures++; + expect.lpz.z = -35.880001068115234000; + if (proj_xyz_dist(expect.xyz, b.xyz) > 1e-4) failures++; if (failures > 1) return 2; - + proj_destroy (P); return 0; -- cgit v1.2.3 From dcd95c505ef188f268671495f7a9950c446d0e72 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Tue, 7 Nov 2017 14:06:05 +0100 Subject: Formally change the initialization type of the TRANSFORMATIONS and CONVERSIONS that are not PROJECTIONS --- src/PJ_vgridshift.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/PJ_vgridshift.c') diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c index 9db0b332..e3f3cbd3 100644 --- a/src/PJ_vgridshift.c +++ b/src/PJ_vgridshift.c @@ -46,7 +46,7 @@ static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) { } -PJ *PROJECTION(vgridshift) { +PJ *TRANSFORMATION(vgridshift,0) { if (!pj_param(P->ctx, P->params, "tgrids").i) { proj_log_error(P, "vgridshift: +grids parameter missing."); -- cgit v1.2.3 From 1d54ce2b6f47b9d60bfd28ad0d33a883be3d510a Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Sun, 12 Nov 2017 14:27:26 +0100 Subject: Poder autochecking again (WIP) (#652) * Poder dual autochecking implementation * Debugging aid: Improvements in PJ_vgridshift.c and gie.c * Most likely, the bugbeing tripped is in the gridshift code, so. uncomment suspicious lines in deformation.gie and merge this to support the debugging effort --- src/PJ_vgridshift.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/PJ_vgridshift.c') diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c index e3f3cbd3..5ab4a162 100644 --- a/src/PJ_vgridshift.c +++ b/src/PJ_vgridshift.c @@ -108,8 +108,8 @@ int pj_vgridshift_selftest (void) { a = proj_coord(0,0,0,0); a.lpz.lam = PJ_TORAD(12.5); a.lpz.phi = PJ_TORAD(55.5); - - dist = proj_roundtrip (P, PJ_FWD, 1, a); + b = a; + dist = proj_roundtrip (P, PJ_FWD, 1, &b); if (dist > 0.00000001) return 1; @@ -125,6 +125,9 @@ int pj_vgridshift_selftest (void) { if (proj_xyz_dist(expect.xyz, b.xyz) > 1e-4) failures++; expect.lpz.z = -35.880001068115234000; if (proj_xyz_dist(expect.xyz, b.xyz) > 1e-4) failures++; + /* manual roundtrip a->b, b<-b, b==a */ + b = proj_trans(P, PJ_INV, b); + if (proj_xyz_dist(a.xyz, b.xyz) > 1e-9) failures++; if (failures > 1) return 2; -- cgit v1.2.3 From 06b2f944d7844bb898ace8a7973f9182aa2234b1 Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Mon, 13 Nov 2017 00:33:40 +0100 Subject: Removed remaining traces of the built in selftest system (#661) * Removed remaining traces of the builtin selftest system. Moved all functionality to test/gie * Updated Appveyor and Travis build scripts * Another appveyor script update --- src/PJ_vgridshift.c | 61 ----------------------------------------------------- 1 file changed, 61 deletions(-) (limited to 'src/PJ_vgridshift.c') diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c index 5ab4a162..97faa240 100644 --- a/src/PJ_vgridshift.c +++ b/src/PJ_vgridshift.c @@ -75,64 +75,3 @@ PJ *TRANSFORMATION(vgridshift,0) { return P; } - -#ifndef PJ_SELFTEST -/* selftest stub */ -int pj_vgridshift_selftest (void) {return 0;} -#else -int pj_vgridshift_selftest (void) { - PJ *P; - PJ_COORD expect, a, b; - double dist; - int failures = 0; - - /* fail on purpose: +grids parameter is mandatory*/ - P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift"); - if (0!=P) { - proj_destroy (P); - return 99; - } - - /* fail on purpose: open non-existing grid */ - P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift +grids=nonexistinggrid.gtx"); - if (0!=P) { - proj_destroy (P); - return 999; - } - - /* Failure most likely means the grid is missing */ - P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift +grids=egm96_15.gtx +ellps=GRS80"); - if (0==P) - return 10; - - a = proj_coord(0,0,0,0); - a.lpz.lam = PJ_TORAD(12.5); - a.lpz.phi = PJ_TORAD(55.5); - b = a; - dist = proj_roundtrip (P, PJ_FWD, 1, &b); - if (dist > 0.00000001) - return 1; - - expect = a; - /* Appears there is a difference between the egm96_15.gtx distributed by OSGeo4W, */ - /* and the one from http://download.osgeo.org/proj/vdatum/egm96_15/egm96_15.gtx */ - /* Was: expect.lpz.z = -36.021305084228515625; (download.osgeo.org) */ - /* Was: expect.lpz.z = -35.880001068115234000; (OSGeo4W) */ - /* This is annoying, but must be handled elsewhere. So for now, we check for both. */ - expect.lpz.z = -36.021305084228516; - failures = 0; - b = proj_trans(P, PJ_FWD, a); - if (proj_xyz_dist(expect.xyz, b.xyz) > 1e-4) failures++; - expect.lpz.z = -35.880001068115234000; - if (proj_xyz_dist(expect.xyz, b.xyz) > 1e-4) failures++; - /* manual roundtrip a->b, b<-b, b==a */ - b = proj_trans(P, PJ_INV, b); - if (proj_xyz_dist(a.xyz, b.xyz) > 1e-9) failures++; - if (failures > 1) - return 2; - - proj_destroy (P); - - return 0; -} -#endif -- cgit v1.2.3