aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2018-03-12 13:38:03 +0100
committerGitHub <noreply@github.com>2018-03-12 13:38:03 +0100
commitd422d4547a1e99ecdedc3bde146ab3c304bc5c6a (patch)
tree3a556f186a77c1fdce10bc972556348fa7964a9b
parenta5ee6c5543aa0d81f37adafc0efc7bffec476e5c (diff)
parent22203cc0677f7f60fd81f719125c3c1768e498ac (diff)
downloadPROJ-d422d4547a1e99ecdedc3bde146ab3c304bc5c6a.tar.gz
PROJ-d422d4547a1e99ecdedc3bde146ab3c304bc5c6a.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.gie16
3 files changed, 60 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 1e84ff30..4c2266fb 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 4b0ecb60..0710edde 100644
--- a/test/gie/4D-API_cs2cs-style.gie
+++ b/test/gie/4D-API_cs2cs-style.gie
@@ -187,6 +187,21 @@ 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).
-------------------------------------------------------------------------------
@@ -200,4 +215,5 @@ accept 487147.594520173 4934316.46263998 0
expect -10370728.80 5552839.74 0
-------------------------------------------------------------------------------
+
</gie>