aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-08-16 14:48:27 +0200
committerGitHub <noreply@github.com>2021-08-16 14:48:27 +0200
commit2924282425cdc953c8e1843e25f7376ece309e11 (patch)
tree5e01b7cd321c8fa2ae9b00cbe60ff6df9b1c2bdf
parent2ddf80a41b90e866ecf113030ff2e241464cb1c8 (diff)
parentfa4c5c645fc5061a306edaef41a9a091189ce528 (diff)
downloadPROJ-2924282425cdc953c8e1843e25f7376ece309e11.tar.gz
PROJ-2924282425cdc953c8e1843e25f7376ece309e11.zip
Merge pull request #2808 from OSGeo/backport-2807-to-8.1
[Backport 8.1] createOperations(): fix missing deg<-->rad conversion when transforming with a CRS that has a fallback-to-PROJ4-string behaviour and is a BoundCRS of a GeographicCRS (fixes #2804)
-rw-r--r--src/iso19111/operation/coordinateoperationfactory.cpp6
-rw-r--r--test/unit/test_operationfactory.cpp24
2 files changed, 28 insertions, 2 deletions
diff --git a/src/iso19111/operation/coordinateoperationfactory.cpp b/src/iso19111/operation/coordinateoperationfactory.cpp
index d63db19e..fc64bd2e 100644
--- a/src/iso19111/operation/coordinateoperationfactory.cpp
+++ b/src/iso19111/operation/coordinateoperationfactory.cpp
@@ -3121,7 +3121,8 @@ void CoordinateOperationFactory::Private::createOperationsFromProj4Ext(
projFormatter->setLegacyCRSToCRSContext(true);
projFormatter->startInversion();
sourceProjExportable->_exportToPROJString(projFormatter.get());
- auto geogSrc = dynamic_cast<const crs::GeographicCRS *>(sourceCRS.get());
+ auto geogSrc = dynamic_cast<const crs::GeographicCRS *>(
+ boundSrc ? boundSrc->baseCRS().get() : sourceCRS.get());
if (geogSrc) {
auto tmpFormatter = io::PROJStringFormatter::create();
geogSrc->addAngularUnitConvertAndAxisSwap(tmpFormatter.get());
@@ -3131,7 +3132,8 @@ void CoordinateOperationFactory::Private::createOperationsFromProj4Ext(
projFormatter->stopInversion();
targetProjExportable->_exportToPROJString(projFormatter.get());
- auto geogDst = dynamic_cast<const crs::GeographicCRS *>(targetCRS.get());
+ auto geogDst = dynamic_cast<const crs::GeographicCRS *>(
+ boundDst ? boundDst->baseCRS().get() : targetCRS.get());
if (geogDst) {
auto tmpFormatter = io::PROJStringFormatter::create();
geogDst->addAngularUnitConvertAndAxisSwap(tmpFormatter.get());
diff --git a/test/unit/test_operationfactory.cpp b/test/unit/test_operationfactory.cpp
index 47c6636c..56d9f743 100644
--- a/test/unit/test_operationfactory.cpp
+++ b/test/unit/test_operationfactory.cpp
@@ -6108,6 +6108,30 @@ TEST(operation, createOperation_fallback_to_proj4_strings) {
// ---------------------------------------------------------------------------
+TEST(operation, createOperation_fallback_to_proj4_strings_bound_of_geog) {
+ auto objSrc = PROJStringParser().createFromPROJString(
+ "+proj=longlat +geoc +ellps=GRS80 +towgs84=0,0,0 +type=crs");
+ auto src = nn_dynamic_pointer_cast<BoundCRS>(objSrc);
+ ASSERT_TRUE(src != nullptr);
+
+ auto objDest = PROJStringParser().createFromPROJString(
+ "+proj=longlat +geoc +ellps=clrk66 +towgs84=0,0,0 +type=crs");
+ auto dest = nn_dynamic_pointer_cast<BoundCRS>(objDest);
+ ASSERT_TRUE(dest != nullptr);
+
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ NN_CHECK_ASSERT(src), NN_CHECK_ASSERT(dest));
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
+ "+proj=pipeline "
+ "+step +proj=unitconvert +xy_in=deg +xy_out=rad "
+ "+step +inv +proj=longlat +geoc +ellps=GRS80 +towgs84=0,0,0 "
+ "+step +proj=longlat +geoc +ellps=clrk66 +towgs84=0,0,0 "
+ "+step +proj=unitconvert +xy_in=rad +xy_out=deg");
+}
+
+// ---------------------------------------------------------------------------
+
TEST(
operation,
createOperation_fallback_to_proj4_strings_regular_with_datum_to_projliteral) {