aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2018-06-06 21:24:11 +0200
committerKristian Evers <kristianevers@gmail.com>2018-06-06 21:24:11 +0200
commit8574765a7fb514b3d8ad7139df4f45a81f95e6c1 (patch)
treec34a871b917f852d9098c51de3aaa48c1fefeca5
parent983d18a01fd0d6a3ecfc1974b919925ae73810f8 (diff)
downloadPROJ-8574765a7fb514b3d8ad7139df4f45a81f95e6c1.tar.gz
PROJ-8574765a7fb514b3d8ad7139df4f45a81f95e6c1.zip
Correct bad use of proj_dmstor in gie.
The previous commits were added way to prematurely. The code was not properly tested and it turned out to do more bad than good. This commit hopefully fixes that. And this time it is backed up by tests! DMS style coordinates should now be fully functional in gie. Finger crossed.
-rw-r--r--src/gie.c20
-rw-r--r--test/gie/more_builtins.gie39
2 files changed, 52 insertions, 7 deletions
diff --git a/src/gie.c b/src/gie.c
index f1e1d167..4c386858 100644
--- a/src/gie.c
+++ b/src/gie.c
@@ -676,7 +676,9 @@ static PJ_COORD parse_coord (const char *args) {
Attempt to interpret args as a PJ_COORD.
******************************************************************************/
int i;
- const char *endp, *prev = args;
+ const char *endp;
+ const char *dmsendp;
+ const char *prev = args;
PJ_COORD a = proj_coord (0,0,0,0);
T.dimensions_given = 0;
@@ -688,14 +690,18 @@ Attempt to interpret args as a PJ_COORD.
/* This could be avoided if proj_dmstor used the same proj_strtod() */
/* as gie, but that is not the case (yet). When we remove projects.h */
/* from the public API we can change that. */
- /* Note that the call to proj_dmstor needs to come first, since it */
- /* returns the wrong endp when reading numbers with _ separators. */
- /* A subsequent call to proj_strtod restores order. */
- double dms = PJ_TODEG(proj_dmstor (prev, (char **) &endp));
- double d = proj_strtod (prev, (char **) &endp);
+ double d = proj_strtod(prev, (char **) &endp);
+ double dms = PJ_TODEG(proj_dmstor (prev, (char **) &dmsendp));
/* TODO: When projects.h is removed, call proj_dmstor() in all cases */
- if (d < dms && dms < d + 1)
+ if (d != dms && fabs(d) < fabs(dms) && fabs(dms) < fabs(d) + 1) {
d = dms;
+ endp = dmsendp;
+ }
+ /* A number like -81d00'00.000 will be parsed correctly by both */
+ /* proj_strtod and proj_dmstor but only the latter will return */
+ /* the correct end-pointer. */
+ if (d == dms && endp != dmsendp)
+ endp = dmsendp;
/* Break out if there were no more numerals */
if (prev==endp)
diff --git a/test/gie/more_builtins.gie b/test/gie/more_builtins.gie
index d7074c5b..04cf724e 100644
--- a/test/gie/more_builtins.gie
+++ b/test/gie/more_builtins.gie
@@ -364,6 +364,45 @@ accept 12 55
expect 69187.5632 609890.7825
-------------------------------------------------------------------------------
+-------------------------------------------------------------------------------
+Test that gie can read DMS style coordinates as well as coordinates where _
+is used as a thousands separator.
+-------------------------------------------------------------------------------
+operation +step +proj=latlong
+-------------------------------------------------------------------------------
+tolerance 1 m
+
+accept -64d43'75.34 17d32'45.6
+expect -64.737589 17.546000
+
+accept 164d43'75.34 17d32'45.6
+expect 164.737589 17.546000
+
+accept 164d43'75.34 17d32'45.6
+expect 164d43'75.34 17d32'45.6
+
+accept 164d43'75.34W 17d32'45.6S
+expect -164.737589 -17.546000
+
+accept 90d00'00.00 0d00'00.00
+expect 90.0 0.0
+
+accept 0d00'00.00 0d00'00.00
+expect 0.0 0.0
+
+
+
+operation +proj=pipeline
+ +step +proj=latlong +datum=NAD27 +inv
+ +step +units=us-ft +init=nad27:3901
+tolerance 1 mm
+
+accept -80d32'30.000 34d32'30.000 0.0
+expect 2_138_028.224 561_330.721 0.0
+
+accept -81d00'00.000 34d32'30.000 0.0
+expect 2_000_000.000 561_019.077 0.0
+-------------------------------------------------------------------------------
-------------------------------------------------------------------------------