From 10a8d5c98499127e5aa61d6cdeee466fcabb12ed Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 29 Feb 2020 13:24:58 +0100 Subject: createOperations(): fix wrong pipeline generation with CRS that has +nadgrids= and +pm= (#1998) Fixes issue reported at https://lists.osgeo.org/pipermail/gdal-dev/2020-February/051749.html The generated pipeline assumes that the input coordinates for the grid transformation were related to the non-Greenwich based datum, so we must compensate for that and add logic to go back to Greenwich. --- src/iso19111/crs.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/iso19111/crs.cpp') diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index dbb68f0b..45e2309c 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -4525,9 +4525,27 @@ BoundCRS::createFromTOWGS84(const CRSNNPtr &baseCRSIn, */ BoundCRSNNPtr BoundCRS::createFromNadgrids(const CRSNNPtr &baseCRSIn, const std::string &filename) { - const CRSPtr sourceGeographicCRS = baseCRSIn->extractGeographicCRS(); + const auto sourceGeographicCRS = baseCRSIn->extractGeographicCRS(); auto transformationSourceCRS = - sourceGeographicCRS ? sourceGeographicCRS : baseCRSIn.as_nullable(); + sourceGeographicCRS + ? NN_NO_CHECK(std::static_pointer_cast(sourceGeographicCRS)) + : baseCRSIn; + if (sourceGeographicCRS != nullptr && + sourceGeographicCRS->datum() != nullptr && + sourceGeographicCRS->primeMeridian()->longitude().getSIValue() != 0.0) { + transformationSourceCRS = GeographicCRS::create( + util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, + sourceGeographicCRS->nameStr() + + " (with Greenwich prime meridian)"), + datum::GeodeticReferenceFrame::create( + util::PropertyMap().set( + common::IdentifiedObject::NAME_KEY, + sourceGeographicCRS->datum()->nameStr() + + " (with Greenwich prime meridian)"), + sourceGeographicCRS->datum()->ellipsoid(), + util::optional(), datum::PrimeMeridian::GREENWICH), + sourceGeographicCRS->coordinateSystem()); + } std::string transformationName = transformationSourceCRS->nameStr(); transformationName += " to WGS84"; @@ -4536,8 +4554,8 @@ BoundCRSNNPtr BoundCRS::createFromNadgrids(const CRSNNPtr &baseCRSIn, operation::Transformation::createNTv2( util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, transformationName), - NN_NO_CHECK(transformationSourceCRS), GeographicCRS::EPSG_4326, - filename, std::vector())); + transformationSourceCRS, GeographicCRS::EPSG_4326, filename, + std::vector())); } // --------------------------------------------------------------------------- -- cgit v1.2.3