aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2018-03-12 13:38:03 +0100
committerKristian Evers <kristianevers@gmail.com>2018-03-12 13:58:49 +0100
commitc4895fdf89254e4969f474355c28d67e7dc7e74d (patch)
treef813ba9c4c585df7d07f380655222ea9068c0390
parent9312b5c1470147660f0dde97bb4007c826bcd1cd (diff)
downloadPROJ-c4895fdf89254e4969f474355c28d67e7dc7e74d.tar.gz
PROJ-c4895fdf89254e4969f474355c28d67e7dc7e74d.zip
Merge pull request #857 from kbevers/return-error-instead-of-zeros
Make sure that transient errors are returned correctly
-rw-r--r--src/pj_fwd.c25
-rw-r--r--src/pj_inv.c25
-rw-r--r--test/gie/4D-API_cs2cs-style.gie28
3 files changed, 72 insertions, 6 deletions
diff --git a/src/pj_fwd.c b/src/pj_fwd.c
index b2e6afd5..ef05962d 100644
--- a/src/pj_fwd.c
+++ b/src/pj_fwd.c
@@ -174,11 +174,22 @@ static PJ_COORD fwd_finalize (PJ *P, PJ_COORD coo) {
}
+static PJ_COORD error_or_coord(PJ *P, PJ_COORD coord, int last_errno) {
+ if (proj_errno(P))
+ return proj_coord_error();
+
+ proj_errno_restore(P, last_errno);
+ return coord;
+}
+
XY pj_fwd(LP lp, PJ *P) {
+ int last_errno;
PJ_COORD coo = {{0,0,0,0}};
coo.lp = lp;
+ last_errno = proj_errno_reset(P);
+
if (!P->skip_fwd_prepare)
coo = fwd_prepare (P, coo);
if (HUGE_VAL==coo.v[0])
@@ -200,15 +211,19 @@ XY pj_fwd(LP lp, PJ *P) {
if (!P->skip_fwd_finalize)
coo = fwd_finalize (P, coo);
- return coo.xy;
+
+ return error_or_coord(P, coo, last_errno).xy;
}
XYZ pj_fwd3d(LPZ lpz, PJ *P) {
+ int last_errno;
PJ_COORD coo = {{0,0,0,0}};
coo.lpz = lpz;
+ last_errno = proj_errno_reset(P);
+
if (!P->skip_fwd_prepare)
coo = fwd_prepare (P, coo);
if (HUGE_VAL==coo.v[0])
@@ -230,12 +245,15 @@ XYZ pj_fwd3d(LPZ lpz, PJ *P) {
if (!P->skip_fwd_finalize)
coo = fwd_finalize (P, coo);
- return coo.xyz;
+
+ return error_or_coord(P, coo, last_errno).xyz;
}
PJ_COORD pj_fwd4d (PJ_COORD coo, PJ *P) {
+ int last_errno = proj_errno_reset(P);
+
if (!P->skip_fwd_prepare)
coo = fwd_prepare (P, coo);
if (HUGE_VAL==coo.v[0])
@@ -257,5 +275,6 @@ PJ_COORD pj_fwd4d (PJ_COORD coo, PJ *P) {
if (!P->skip_fwd_finalize)
coo = fwd_finalize (P, coo);
- return coo;
+
+ return error_or_coord(P, coo, last_errno);
}
diff --git a/src/pj_inv.c b/src/pj_inv.c
index 7f1889f3..f2901ca0 100644
--- a/src/pj_inv.c
+++ b/src/pj_inv.c
@@ -172,11 +172,22 @@ static PJ_COORD inv_finalize (PJ *P, PJ_COORD coo) {
}
+static PJ_COORD error_or_coord(PJ *P, PJ_COORD coord, int last_errno) {
+ if (proj_errno(P))
+ return proj_coord_error();
+
+ proj_errno_restore(P, last_errno);
+ return coord;
+}
+
LP pj_inv(XY xy, PJ *P) {
+ int last_errno;
PJ_COORD coo = {{0,0,0,0}};
coo.xy = xy;
+ last_errno = proj_errno_reset(P);
+
if (!P->skip_inv_prepare)
coo = inv_prepare (P, coo);
if (HUGE_VAL==coo.v[0])
@@ -198,15 +209,19 @@ LP pj_inv(XY xy, PJ *P) {
if (!P->skip_inv_finalize)
coo = inv_finalize (P, coo);
- return coo.lp;
+
+ return error_or_coord(P, coo, last_errno).lp;
}
LPZ pj_inv3d (XYZ xyz, PJ *P) {
+ int last_errno;
PJ_COORD coo = {{0,0,0,0}};
coo.xyz = xyz;
+ last_errno = proj_errno_reset(P);
+
if (!P->skip_inv_prepare)
coo = inv_prepare (P, coo);
if (HUGE_VAL==coo.v[0])
@@ -228,12 +243,15 @@ LPZ pj_inv3d (XYZ xyz, PJ *P) {
if (!P->skip_inv_finalize)
coo = inv_finalize (P, coo);
- return coo.lpz;
+
+ return error_or_coord(P, coo, last_errno).lpz;
}
PJ_COORD pj_inv4d (PJ_COORD coo, PJ *P) {
+ int last_errno = proj_errno_reset(P);
+
if (!P->skip_inv_prepare)
coo = inv_prepare (P, coo);
if (HUGE_VAL==coo.v[0])
@@ -255,5 +273,6 @@ PJ_COORD pj_inv4d (PJ_COORD coo, PJ *P) {
if (!P->skip_inv_finalize)
coo = inv_finalize (P, coo);
- return coo;
+
+ return error_or_coord(P, coo, last_errno);
}
diff --git a/test/gie/4D-API_cs2cs-style.gie b/test/gie/4D-API_cs2cs-style.gie
index 66da0633..b7c37c83 100644
--- a/test/gie/4D-API_cs2cs-style.gie
+++ b/test/gie/4D-API_cs2cs-style.gie
@@ -186,4 +186,32 @@ tolerance 20 cm
accept 7.438632495 46.951082877
expect 2600000.0 1200000.0
-------------------------------------------------------------------------------
+
+-------------------------------------------------------------------------------
+Make sure that transient errors are returned correctly.
+-------------------------------------------------------------------------------
+operation +proj=geos +lon_0=0.00 +lat_0=0.00 +a=6378169.00 +b=6356583.80 +h=35785831.0
+-------------------------------------------------------------------------------
+accept 85.05493299 46.5261074
+expect failure
+
+accept 85.05493299 46.5261074 0
+expect failure
+
+accept 85.05493299 46.5261074 0 0
+expect failure
+
+-------------------------------------------------------------------------------
+Test that Google's Web Mercator works as intended (see #834 for details).
+-------------------------------------------------------------------------------
+operation proj=pipeline step init=epsg:26915 inv step init=epsg:3857
+-------------------------------------------------------------------------------
+tolerance 20 cm
+accept 487147.594520173 4934316.46263998
+expect -10370728.80 5552839.74
+
+accept 487147.594520173 4934316.46263998 0
+expect -10370728.80 5552839.74 0
+-------------------------------------------------------------------------------
+
</gie>