Skip to content

Commit

Permalink
Improve tests for gridshift drivers. Made sure Travis has PROJ_LIB en…
Browse files Browse the repository at this point in the history
…vironment variable set when calling selftest. Now testing both failing initializations, roundtrip and known values after grid has been applied.
  • Loading branch information
kbevers committed Mar 1, 2017
1 parent a6f539e commit 1a77647
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
28 changes: 21 additions & 7 deletions src/PJ_hgridshift.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,23 @@ int pj_hgridshift_selftest (void) {return 0;}
#else
int pj_hgridshift_selftest (void) {
PJ *P;
PJ_OBS a;
PJ_OBS expect, a, b;
double dist;

/* Since the nzgd2kgrid0005.gsb grid is not part of the
* basic PROJ.4 distribution we only include it as an
* optional grid in the test. The test is fairly useless
* if the grid isn't found, but at least it won't fail
* because of a missing file */
P = pj_create ("+proj=hgridshift +grids=@nzgd2kgrid0005.gsb +ellps=GRS80");
/* fail on purpose: +grids parameter it mandatory*/
P = pj_create("+proj=hgridshift");
if (0!=P)
return 99;

/* fail on purpose: open non-existing grid */
P = pj_create("+proj=hgridshift +grids=nonexistinggrid.gsb");
if (0!=P)
return 999;


P = pj_create ("+proj=hgridshift +grids=nzgd2kgrid0005.gsb +ellps=GRS80");
if (0==P)
/* very likely the grid is missing */
return 10;

a = pj_obs_null;
Expand All @@ -124,6 +131,13 @@ int pj_hgridshift_selftest (void) {
if (dist > 0.00000001)
return 1;

expect.coo.lpz.lam = TORAD(172.999892181021551);
expect.coo.lpz.phi = TORAD(-45.001620431954613);
b = pj_trans(P, PJ_FWD, a);
if (pj_xy_dist(expect.coo.xy, b.coo.xy) > 1e-4)
return 2;


pj_free(P);

return 0;
Expand Down
30 changes: 22 additions & 8 deletions src/PJ_vgridshift.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static XYZ forward_3d(LPZ lpz, PJ *P) {
pj_apply_vgridshift( P, "sgrids",
&(P->vgridlist_geoid),
&(P->vgridlist_geoid_count),
0, 1, 0,
1, 1, 0,
&point.xyz.x, &point.xyz.y, &point.xyz.z );
}

Expand All @@ -49,7 +49,7 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) {
pj_apply_vgridshift( P, "sgrids",
&(P->vgridlist_geoid),
&(P->vgridlist_geoid_count),
1, 1, 0,
0, 1, 0,
&point.xyz.x, &point.xyz.y, &point.xyz.z );
}

Expand Down Expand Up @@ -107,15 +107,22 @@ int pj_vgridshift_selftest (void) {return 0;}
#else
int pj_vgridshift_selftest (void) {
PJ *P;
PJ_OBS a;
PJ_OBS expect, a, b;
double dist;

/* Since the egm96 grid is not part of the basic PROJ.4 distribution we
* only include it as a optional grid in the test.
* The test is fairly useless if the grid isn't found, but at least it
* won't fail because of a missing file */
P = pj_create ("+proj=vgridshift +grids=@egm96_15.gtx +ellps=GRS80");
/* fail on purpose: +grids parameter it mandatory*/
P = pj_create("+proj=vgridshift");
if (0!=P)
return 99;

/* fail on purpose: open non-existing grid */
P = pj_create("+proj=vgridshift +grids=nonexistinggrid.gtx");
if (0!=P)
return 999;

P = pj_create ("+proj=vgridshift +grids=egm96_15.gtx +ellps=GRS80");
if (0==P)
/* most likely the grid wasn't found */
return 10;

a = pj_obs_null;
Expand All @@ -126,6 +133,13 @@ int pj_vgridshift_selftest (void) {
if (dist > 0.00000001)
return 1;

expect = a;
expect.coo.lpz.z = -36.021305084228515625;
b = pj_trans(P, PJ_FWD, a);
if (pj_xyz_dist(expect.coo.xyz, b.coo.xyz) > 1e-10)
return 2;


pj_free(P);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ if [ $TRAVIS_OS_NAME == "osx" ]; then
fi
make -j3
make check
./src/proj -VC
PROJ_LIB=../nad ./src/proj -VC

# install & run the working GIGS test
# create locations that pyproj understands
python3 --version
Expand Down

0 comments on commit 1a77647

Please sign in to comment.