From efc958e953b8c4a7fe9eaa7015d94c8456968bd4 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 10 Mar 2022 10:48:39 +0100 Subject: Merge pull request #3108 from rouault/fix_3095 createOperations(): fix issue in transformation northing,easting projected CRS -> +proj=longlat +lon_wrap (fixes #3095) --- src/iso19111/crs.cpp | 3 ++- test/unit/test_operationfactory.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index 881aec0b..e4b8094f 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -4404,7 +4404,8 @@ void ProjectedCRS::addUnitConvertAndAxisSwap(io::PROJStringFormatter *formatter, formatter->addParam("units", "m"); } - if (!axisSpecFound && !formatter->getCRSExport()) { + if (!axisSpecFound && + (!formatter->getCRSExport() || formatter->getLegacyCRSToCRSContext())) { const auto &dir0 = axisList[0]->direction(); const auto &dir1 = axisList[1]->direction(); if (!(&dir0 == &cs::AxisDirection::EAST && diff --git a/test/unit/test_operationfactory.cpp b/test/unit/test_operationfactory.cpp index 89c4e7c4..0c3ecae4 100644 --- a/test/unit/test_operationfactory.cpp +++ b/test/unit/test_operationfactory.cpp @@ -6569,6 +6569,32 @@ TEST(operation, createOperation_on_crs_with_bound_crs_and_wktext) { // --------------------------------------------------------------------------- +TEST(operation, + createOperation_fallback_to_proj4_strings_with_axis_inverted_projCRS) { + auto objSrc = + createFromUserInput("EPSG:2193", DatabaseContext::create(), false); + auto src = nn_dynamic_pointer_cast(objSrc); + ASSERT_TRUE(src != nullptr); + + auto objDest = PROJStringParser().createFromPROJString( + "+proj=longlat +ellps=WGS84 +lon_wrap=180 +type=crs"); + auto dest = nn_dynamic_pointer_cast(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=axisswap +order=2,1 " + "+step +inv +proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 " + "+x_0=1600000 +y_0=10000000 +ellps=GRS80 " + "+step +proj=longlat +ellps=WGS84 +lon_wrap=180 " + "+step +proj=unitconvert +xy_in=rad +xy_out=deg"); +} + +// --------------------------------------------------------------------------- + TEST(operation, compoundCRS_to_proj_string_with_non_metre_height) { auto objSrc = createFromUserInput("EPSG:6318+5703", DatabaseContext::create(), false); -- cgit v1.2.3