Skip to content

Commit

Permalink
PROJ string ingestion: adds +towgs84= when expanding +init=epsg:XXXX (f…
Browse files Browse the repository at this point in the history
…ixes OSGeo#1597)

Currently, +init=epsg:XXXX expansion from proj.db didn't make any effort
to try to add a +towgs84 clause. Now this will do using CRS::createBoundCRSToWGS84IfPossible()
Note that however this does not perfectly emulated PROJ4/PROJ5 epsg file
behaviour, and will only add a +towgs84 when it is valid for the whole
area of use of the CRS, whereas PROJ4/PROJ5 would add the one that was
valid for the largest sub-area of use.
The additiong of a +towgs84 clause will be thus more likely for a
projected CRS valid for a country, rather than for a geographic CRS valid
for a continent or a larger area, and thus whose transformations to WGS84
might be multiple.
The consequence of this shows up in some GIGS test that must be adapted to
add an explicit +towgs84 for source/target geographic CRS with value equal
to the one of the source/target projected CRS.
  • Loading branch information
rouault committed Sep 11, 2019
1 parent 9fea5bf commit 18c553a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
8 changes: 7 additions & 1 deletion src/init.cpp
Expand Up @@ -38,6 +38,7 @@

#include "geodesic.h"
#include "proj.h"
#include "proj_experimental.h"
#include "proj_internal.h"
#include "proj_math.h"

Expand Down Expand Up @@ -289,8 +290,12 @@ Expand key from buffer or (if not in buffer) from init file
return nullptr;
}

proj_string = proj_as_proj_string(ctx, src, PJ_PROJ_4, nullptr);
auto boundCRS = proj_crs_create_bound_crs_to_WGS84(ctx, src, nullptr);

proj_string = proj_as_proj_string(ctx, boundCRS ? boundCRS : src, PJ_PROJ_4, nullptr);

if( !proj_string ) {
proj_destroy(boundCRS);
proj_destroy(src);
return nullptr;
}
Expand All @@ -299,6 +304,7 @@ Expand key from buffer or (if not in buffer) from init file
strcpy(definition, proj_string);
}

proj_destroy(boundCRS);
proj_destroy(src);
}
}
Expand Down
19 changes: 17 additions & 2 deletions src/iso19111/io.cpp
Expand Up @@ -8821,8 +8821,23 @@ PROJStringParser::createFromPROJString(const std::string &projString) {
}
}
expanded += ' ';
expanded += projStringExportable->exportToPROJString(
PROJStringFormatter::create().get());

auto boundToWGS84 = crs->createBoundCRSToWGS84IfPossible(
d->dbContext_,
CoordinateOperationContext::IntermediateCRSUse::NEVER);
auto projStringExportableBoundToWGS84 =
dynamic_cast<IPROJStringExportable *>(
boundToWGS84.get());
if (projStringExportableBoundToWGS84) {
expanded +=
projStringExportableBoundToWGS84
->exportToPROJString(
PROJStringFormatter::create().get());
} else {
expanded += projStringExportable->exportToPROJString(
PROJStringFormatter::create().get());
}

return createFromPROJString(expanded);
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/gigs/5102.1.gie
Expand Up @@ -10,7 +10,7 @@ use_proj4_init_rules true

--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:4230 +inv
+step +init=epsg:4230 +towgs84=-84,-97,-117,0,0,0,0 +inv
+step +init=epsg:2192
--------------------------------------------------------------------------------
tolerance 0.03 m
Expand Down Expand Up @@ -92,7 +92,7 @@ expect 1183924.412 2923146.858
--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:2192 +inv
+step +init=epsg:4230
+step +init=epsg:4230 +towgs84=-84,-97,-117,0,0,0,0
--------------------------------------------------------------------------------
tolerance 0.03 m
accept 760722.92 3457368.68
Expand Down Expand Up @@ -172,7 +172,7 @@ expect 11 53

--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:4230 +inv
+step +init=epsg:4230 +towgs84=-84,-97,-117,0,0,0,0 +inv
+step +init=epsg:2192
--------------------------------------------------------------------------------
tolerance 0.006 m
Expand Down
8 changes: 4 additions & 4 deletions test/gigs/5103.1.gie
Expand Up @@ -10,7 +10,7 @@ use_proj4_init_rules true

--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:4313 +inv
+step +init=epsg:4313 +towgs84=-99.059,53.322,-112.486,0.419,-0.83,1.885,-1 +inv
+step +init=epsg:31370

tolerance 30 mm
Expand Down Expand Up @@ -47,7 +47,7 @@ expect 123101.889 -34711.068

accept 3.3137281 47.9752611
expect 71254.553 -148236.592

+init=epsg:4313
accept 3 53
expect 58108.966 411155.591

Expand Down Expand Up @@ -79,7 +79,7 @@ expect 595117.95 430202.63
--------------------------------------------------------------------------------
operation proj=pipeline
step init=epsg:31370 inv
step init=epsg:4313
step init=epsg:4313 towgs84=-99.059,53.322,-112.486,0.419,-0.83,1.885,-1

tolerance 30 mm
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -145,7 +145,7 @@ expect 11 53

--------------------------------------------------------------------------------
operation +proj=pipeline towgs84=0,0,0 # turn off dual datum shift
+step +init=epsg:4313 +inv
+step +init=epsg:4313 +towgs84=-99.059,53.322,-112.486,0.419,-0.83,1.885,-1 +inv
+step +init=epsg:31370

tolerance 6 mm
Expand Down
6 changes: 3 additions & 3 deletions test/gigs/5105.2.gie
Expand Up @@ -10,7 +10,7 @@ use_proj4_init_rules true

--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:4237 +inv
+step +init=epsg:4237 +towgs84=52.684,-71.194,-13.975,-0.312,-0.1063,-0.3729,1.0191 +inv
+step +init=epsg:23700
--------------------------------------------------------------------------------
tolerance 0.05 m
Expand Down Expand Up @@ -64,7 +64,7 @@ expect 439836.709 20816.456
--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:23700 +inv
+step +init=epsg:4237
+step +init=epsg:4237 +towgs84=52.684,-71.194,-13.975,-0.312,-0.1063,-0.3729,1.0191
--------------------------------------------------------------------------------
tolerance 0.05 m
accept 424714.235 355124.6
Expand Down Expand Up @@ -116,7 +116,7 @@ expect 16.36 45.5

--------------------------------------------------------------------------------
operation +proj=pipeline
+step +init=epsg:4237 +inv
+step +init=epsg:4237 +towgs84=52.684,-71.194,-13.975,-0.312,-0.1063,-0.3729,1.0191 +inv
+step +init=epsg:23700
--------------------------------------------------------------------------------
tolerance 0.006 m
Expand Down
6 changes: 3 additions & 3 deletions test/gigs/5112.gie
Expand Up @@ -10,7 +10,7 @@ use_proj4_init_rules true

--------------------------------------------------------------------------------
operation proj=pipeline
step init=epsg:4284 inv
step init=epsg:4284 towgs84=25,-141,-78.5,0,0.35,0.736,0 inv
step init=epsg:3388

tolerance 50 mm
Expand All @@ -33,7 +33,7 @@ expect 1325634.35 -3709687.25
--------------------------------------------------------------------------------
operation proj=pipeline
step init=epsg:3388 inv
step init=epsg:4284
step init=epsg:4284 towgs84=25,-141,-78.5,0,0.35,0.736,0

tolerance 50 mm
--------------------------------------------------------------------------------
Expand All @@ -54,7 +54,7 @@ expect 67.0 -41.0

--------------------------------------------------------------------------------
operation proj=pipeline towgs84=0,0,0
step init=epsg:4284 inv
step init=epsg:4284 towgs84=25,-141,-78.5,0,0.35,0.736,0 inv
step init=epsg:3388

tolerance 6 mm
Expand Down

0 comments on commit 18c553a

Please sign in to comment.