From a2f8fd1a21da1352a39cc56db2bb39613fc29091 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 15 May 2020 00:40:25 +0200 Subject: Make projinfo --3d --boundcrs-to-wgs84 better work (fixes #2202) --- src/iso19111/coordinateoperation.cpp | 25 +++++++++++++++++++++++++ src/iso19111/crs.cpp | 28 ++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp index 0f5e4c4d..6b552721 100644 --- a/src/iso19111/coordinateoperation.cpp +++ b/src/iso19111/coordinateoperation.cpp @@ -6590,6 +6590,31 @@ TransformationNNPtr Transformation::shallowClone() const { CoordinateOperationNNPtr Transformation::_shallowClone() const { return util::nn_static_pointer_cast(shallowClone()); } + +// --------------------------------------------------------------------------- + +TransformationNNPtr +Transformation::promoteTo3D(const std::string &, + const io::DatabaseContextPtr &dbContext) const { + auto transf = shallowClone(); + transf->setCRSs(sourceCRS()->promoteTo3D(std::string(), dbContext), + targetCRS()->promoteTo3D(std::string(), dbContext), + interpolationCRS()); + return transf; +} + +// --------------------------------------------------------------------------- + +TransformationNNPtr +Transformation::demoteTo2D(const std::string &, + const io::DatabaseContextPtr &dbContext) const { + auto transf = shallowClone(); + transf->setCRSs(sourceCRS()->demoteTo2D(std::string(), dbContext), + targetCRS()->demoteTo2D(std::string(), dbContext), + interpolationCRS()); + return transf; +} + //! @endcond // --------------------------------------------------------------------------- diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index c23bd29b..0d461d64 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -902,9 +902,17 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName, const auto boundCRS = dynamic_cast(this); if (boundCRS) { - return BoundCRS::create( - boundCRS->baseCRS()->promoteTo3D(newName, dbContext), - boundCRS->hubCRS(), boundCRS->transformation()); + auto base3DCRS = boundCRS->baseCRS()->promoteTo3D(newName, dbContext); + auto transf = boundCRS->transformation(); + try { + transf->getTOWGS84Parameters(); + return BoundCRS::create( + base3DCRS, + boundCRS->hubCRS()->promoteTo3D(std::string(), dbContext), + transf->promoteTo3D(std::string(), dbContext)); + } catch (const io::FormattingException &) { + return BoundCRS::create(base3DCRS, boundCRS->hubCRS(), transf); + } } return NN_NO_CHECK( @@ -937,9 +945,17 @@ CRSNNPtr CRS::demoteTo2D(const std::string &newName, const auto boundCRS = dynamic_cast(this); if (boundCRS) { - return BoundCRS::create( - boundCRS->baseCRS()->demoteTo2D(newName, dbContext), - boundCRS->hubCRS(), boundCRS->transformation()); + auto base2DCRS = boundCRS->baseCRS()->demoteTo2D(newName, dbContext); + auto transf = boundCRS->transformation(); + try { + transf->getTOWGS84Parameters(); + return BoundCRS::create( + base2DCRS, + boundCRS->hubCRS()->demoteTo2D(std::string(), dbContext), + transf->demoteTo2D(std::string(), dbContext)); + } catch (const io::FormattingException &) { + return BoundCRS::create(base2DCRS, boundCRS->hubCRS(), transf); + } } const auto compoundCRS = dynamic_cast(this); -- cgit v1.2.3