aboutsummaryrefslogtreecommitdiff
path: root/src/PJ_vgridshift.c
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2017-10-09 21:55:30 +0200
committerKristian Evers <kristianevers@gmail.com>2017-10-09 21:55:30 +0200
commit0d4ce7814091a716fc835eb3abe3ad41d49f3ee1 (patch)
tree2404ee17446b91fe4c776445ad2b30db866ed8ef /src/PJ_vgridshift.c
parentf8d26297de7f6092e78bcd33876510c7082c3f35 (diff)
parent8fc250a04edbfe81b9b7409187887066baeba29b (diff)
downloadPROJ-0d4ce7814091a716fc835eb3abe3ad41d49f3ee1.tar.gz
PROJ-0d4ce7814091a716fc835eb3abe3ad41d49f3ee1.zip
Merge remote-tracking branch 'osgeo/master' into docs-release-4.10.0
Diffstat (limited to 'src/PJ_vgridshift.c')
-rw-r--r--src/PJ_vgridshift.c61
1 files changed, 28 insertions, 33 deletions
diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c
index e790cd4d..ededd544 100644
--- a/src/PJ_vgridshift.c
+++ b/src/PJ_vgridshift.c
@@ -1,25 +1,9 @@
#define PJ_LIB__
#include "proj_internal.h"
-#include <projects.h>
+#include "projects.h"
PROJ_HEAD(vgridshift, "Vertical grid shift");
-static void *freeup_msg (PJ *P, int errlev) {
- if (0==P)
- return 0;
-
- if (0!=P->ctx)
- pj_ctx_set_errno (P->ctx, errlev);
-
- return pj_dealloc(P);
-}
-
-
-static void freeup (PJ *P) {
- freeup_msg (P, 0);
- return;
-}
-
static XYZ forward_3d(LPZ lpz, PJ *P) {
PJ_TRIPLET point;
@@ -74,7 +58,7 @@ PJ *PROJECTION(vgridshift) {
if (!pj_param(P->ctx, P->params, "tgrids").i) {
proj_log_error(P, "vgridshift: +grids parameter missing.");
- return freeup_msg(P, -1);
+ return pj_default_destructor(P, PJD_ERR_NO_ARGS);
}
/* Build gridlist. P->gridlist can be empty if +grids only ask for optional grids. */
@@ -84,9 +68,7 @@ PJ *PROJECTION(vgridshift) {
/* Was gridlist compiled properly? */
if ( pj_ctx_get_errno(P->ctx) ) {
proj_log_error(P, "vgridshift: could not find required grid(s).");
- pj_dalloc(P->gridlist);
- P->gridlist = NULL;
- return freeup_msg(P, -38);
+ return pj_default_destructor(P, -38);
}
P->fwdobs = forward_obs;
@@ -111,19 +93,24 @@ int pj_vgridshift_selftest (void) {
PJ *P;
PJ_OBS expect, a, b;
double dist;
+ int failures = 0;
- /* fail on purpose: +grids parameter it mandatory*/
- P = proj_create(0, "+proj=vgridshift");
- if (0!=P)
+ /* 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(0, "+proj=vgridshift +grids=nonexistinggrid.gtx");
- if (0!=P)
+ 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 (0, "+proj=vgridshift +grids=egm96_15.gtx +ellps=GRS80");
+ P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift +grids=egm96_15.gtx +ellps=GRS80");
if (0==P)
return 10;
@@ -131,18 +118,26 @@ int pj_vgridshift_selftest (void) {
a.coo.lpz.lam = PJ_TORAD(12.5);
a.coo.lpz.phi = PJ_TORAD(55.5);
- dist = proj_roundtrip (P, PJ_FWD, 1, a);
+ dist = proj_roundtrip (P, PJ_FWD, 1, a.coo);
if (dist > 0.00000001)
return 1;
expect = a;
- expect.coo.lpz.z = -36.021305084228515625;
+ /* 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) */
+ /* This is annoying, but must be handled elsewhere. So for now, we check for both. */
+ expect.coo.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-10)
+ 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++;
+ if (failures > 1)
return 2;
-
-
- pj_free(P);
+
+ proj_destroy (P);
return 0;
}