From d0dbf48438f9e152314abf294467cb54f9ae0e70 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Mon, 22 Jan 2018 21:06:23 +0100 Subject: [PATCH] Handle ellipsoid parameters correctly when using +nadgrids=@null. Fixes #22. Make sure to not change ellipsoid parameters to WGS84 when applying the null grid. Coordinates will still refer to the input ellipsoid so we keep the original parameters which in turn will be used when the coordinates are transformated to/from cartesian/geocentric space. Adjusted regression test material in nad/proj_outIGNF.dist slightly to accomodate numerical differences at the mm level. The transformations in question are at best accurate to about 1m so this shouldn't change real world usage of these transformations. --- nad/proj_outIGNF.dist | 10 +++++----- src/pj_transform.c | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/nad/proj_outIGNF.dist b/nad/proj_outIGNF.dist index 45112f6049..be666fb0a2 100644 --- a/nad/proj_outIGNF.dist +++ b/nad/proj_outIGNF.dist @@ -1,16 +1,16 @@ +init=./IGNF:NTFG +to +init=./IGNF:RGF93G 3.300866856 43.4477976569 0.0000 3d18'0.915"E 43d26'52.077"N 0.000 +init=./IGNF:LAMBE +to +init=./IGNF:LAMB93 - 600000.0000 2600545.4523 0.0000 652760.737 7033791.243 0.000 + 600000.0000 2600545.4523 0.0000 652760.737 7033791.244 0.000 135638.3592 2418760.4094 0.0000 187194.062 6855928.882 0.000 998137.3947 2413822.2844 0.0000 1049052.258 6843776.562 0.000 - 600000.0000 2200000.0000 0.0000 649398.872 6633524.191 0.000 + 600000.0000 2200000.0000 0.0000 649398.872 6633524.192 0.000 311552.5340 1906457.4840 0.0000 358799.172 6342652.486 0.000 960488.4138 1910172.8812 0.0000 1007068.686 6340907.237 0.000 600000.0000 1699510.8340 0.0000 645204.279 6133556.746 0.000 -1203792.5981 626873.17210 0.0000 1238875.764 5057405.016 0.000 +1203792.5981 626873.17210 0.0000 1238875.764 5057405.017 0.000 +init=./IGNF:LAMBE +to +init=./IGNF:GEOPORTALFXX - 600000.0000 2600545.4523 0.0000 179040.148 5610495.275 0.000 + 600000.0000 2600545.4523 0.0000 179040.148 5610495.276 0.000 135638.3592 2418760.4094 0.0000 -303729.363 5410118.356 0.000 998137.3947 2413822.2844 0.0000 592842.792 5410120.554 0.000 600000.0000 2200000.0000 0.0000 179041.670 5209746.080 0.000 @@ -37,4 +37,4 @@ 2d20'11.7754730" 42d18'00.0824436" 0.0 260109.601 5009175.714 0.000 9d32'12.6680218" 41d24'00.3542556" 0.0 1061637.534 4889066.592 0.000 +init=./IGNF:RGR92 +to +init=./IGNF:REUN47 -3356123.5400 1303218.3090 5247430.6050 3353421.833 1304074.314 5248935.607 +3356123.5400 1303218.3090 5247430.6050 3353421.833 1304074.314 5248935.606 diff --git a/src/pj_transform.c b/src/pj_transform.c index c72df2e764..6ad227cd8e 100644 --- a/src/pj_transform.c +++ b/src/pj_transform.c @@ -748,17 +748,30 @@ int pj_datum_transform( PJ *srcdefn, PJ *dstdefn, /* -------------------------------------------------------------------- */ if( srcdefn->datum_type == PJD_GRIDSHIFT ) { + const char* srcnadgrids = pj_param(srcdefn->ctx, srcdefn->params,"snadgrids").s; + pj_apply_gridshift_2( srcdefn, 0, point_count, point_offset, x, y, z ); CHECK_RETURN(srcdefn); - src_a = SRS_WGS84_SEMIMAJOR; - src_es = SRS_WGS84_ESQUARED; + /* If the gridlist has either "@null" or "null" as its only */ + /* grid we don't change the ellipsoid parameters, since the */ + /* datum shift to WGS84 was not performed in practice. */ + if ( strcmp("@null", srcnadgrids) && strcmp("null", srcnadgrids) ) { + src_a = SRS_WGS84_SEMIMAJOR; + src_es = SRS_WGS84_ESQUARED; + } } if( dstdefn->datum_type == PJD_GRIDSHIFT ) { - dst_a = SRS_WGS84_SEMIMAJOR; - dst_es = SRS_WGS84_ESQUARED; + const char* dstnadgrids = pj_param(dstdefn->ctx, dstdefn->params,"snadgrids").s; + /* If the gridlist has either "@null" or "null" as its only */ + /* grid we don't change the ellipsoid parameters, since the */ + /* datum shift to WGS84 will not be performed. */ + if ( strcmp("@null", dstnadgrids) && strcmp("null", dstnadgrids) ) { + dst_a = SRS_WGS84_SEMIMAJOR; + dst_es = SRS_WGS84_ESQUARED; + } } /* ==================================================================== */