diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2021-04-10 22:09:29 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2021-04-12 11:51:30 +0200 |
| commit | e03a9aacec01aa8082304c192f34fd26b95a5e11 (patch) | |
| tree | 1cad5b34636f9e75b08454ea18e9cc23735c6a74 | |
| parent | a42b447021a2f337d66d1e30d4880cd2be08932a (diff) | |
| download | PROJ-e03a9aacec01aa8082304c192f34fd26b95a5e11.tar.gz PROJ-e03a9aacec01aa8082304c192f34fd26b95a5e11.zip | |
CRS::normalizeForVisualization(): propagate domains/extent of original CRS (fixes #2603)
| -rw-r--r-- | src/iso19111/crs.cpp | 64 | ||||
| -rw-r--r-- | test/unit/test_crs.cpp | 4 |
2 files changed, 59 insertions, 9 deletions
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index 20cf54c9..39097e68 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -822,21 +822,58 @@ bool CRS::mustAxisOrderBeSwitchedForVisualization() const { //! @cond Doxygen_Suppress CRSNNPtr CRS::normalizeForVisualization() const { - auto props = util::PropertyMap().set( - common::IdentifiedObject::NAME_KEY, - nameStr() + " (with axis order normalized for visualization)"); + + const auto createProperties = [this](const std::string &newName = + std::string()) { + auto props = util::PropertyMap().set( + common::IdentifiedObject::NAME_KEY, + !newName.empty() + ? newName + : nameStr() + + " (with axis order normalized for visualization)"); + const auto &l_domains = domains(); + if (!l_domains.empty()) { + auto array = util::ArrayOfBaseObject::create(); + for (const auto &domain : l_domains) { + array->add(domain); + } + if (!array->empty()) { + props.set(common::ObjectUsage::OBJECT_DOMAIN_KEY, array); + } + } + const auto &l_identifiers = identifiers(); + const auto &l_remarks = remarks(); + if (l_identifiers.size() == 1) { + std::string remarks("Axis order reversed compared to "); + remarks += *(l_identifiers[0]->codeSpace()); + remarks += ':'; + remarks += l_identifiers[0]->code(); + if (!l_remarks.empty()) { + remarks += ". "; + remarks += l_remarks; + } + props.set(common::IdentifiedObject::REMARKS_KEY, remarks); + } else if (!l_remarks.empty()) { + props.set(common::IdentifiedObject::REMARKS_KEY, l_remarks); + } + return props; + }; const CompoundCRS *compoundCRS = dynamic_cast<const CompoundCRS *>(this); if (compoundCRS) { const auto &comps = compoundCRS->componentReferenceSystems(); - if (!comps.empty()) { + if (!comps.empty() && + comps[0]->mustAxisOrderBeSwitchedForVisualization()) { std::vector<CRSNNPtr> newComps; newComps.emplace_back(comps[0]->normalizeForVisualization()); + std::string l_name = newComps.back()->nameStr(); for (size_t i = 1; i < comps.size(); i++) { newComps.emplace_back(comps[i]); + l_name += " + "; + l_name += newComps.back()->nameStr(); } return util::nn_static_pointer_cast<CRS>( - CompoundCRS::create(props, newComps)); + CompoundCRS::create(createProperties(l_name), newComps)); } } @@ -850,8 +887,9 @@ CRSNNPtr CRS::normalizeForVisualization() const { : cs::EllipsoidalCS::create(util::PropertyMap(), axisList[1], axisList[0], axisList[2]); - return util::nn_static_pointer_cast<CRS>(GeographicCRS::create( - props, geogCRS->datum(), geogCRS->datumEnsemble(), cs)); + return util::nn_static_pointer_cast<CRS>( + GeographicCRS::create(createProperties(), geogCRS->datum(), + geogCRS->datumEnsemble(), cs)); } } @@ -865,8 +903,9 @@ CRSNNPtr CRS::normalizeForVisualization() const { axisList[0]) : cs::CartesianCS::create(util::PropertyMap(), axisList[1], axisList[0], axisList[2]); - return util::nn_static_pointer_cast<CRS>(ProjectedCRS::create( - props, projCRS->baseCRS(), projCRS->derivingConversion(), cs)); + return util::nn_static_pointer_cast<CRS>( + ProjectedCRS::create(createProperties(), projCRS->baseCRS(), + projCRS->derivingConversion(), cs)); } } @@ -1019,12 +1058,19 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName, } } const auto &l_identifiers = identifiers(); + const auto &l_remarks = remarks(); if (l_identifiers.size() == 1) { std::string remarks("Promoted to 3D from "); remarks += *(l_identifiers[0]->codeSpace()); remarks += ':'; remarks += l_identifiers[0]->code(); + if (!l_remarks.empty()) { + remarks += ". "; + remarks += l_remarks; + } props.set(common::IdentifiedObject::REMARKS_KEY, remarks); + } else if (!l_remarks.empty()) { + props.set(common::IdentifiedObject::REMARKS_KEY, l_remarks); } return props; }; diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index 5ff4dd2d..719cd125 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -1002,6 +1002,10 @@ TEST(crs, EPSG_32661_projected_north_pole_north_east) { EXPECT_EQ( opNormalized->exportToPROJString(PROJStringFormatter::create().get()), proj_string_normalized); + + EXPECT_EQ(opNormalized->sourceCRS()->domains().size(), 1U); + EXPECT_EQ(opNormalized->sourceCRS()->remarks(), + "Axis order reversed compared to EPSG:4326"); } // --------------------------------------------------------------------------- |
