From 5f66a942a57783c2f11fead602b2442ea291c019 Mon Sep 17 00:00:00 2001 From: Javier Jimenez Shaw Date: Sat, 19 Nov 2022 12:32:31 +0100 Subject: [PATCH] add implementation for stripVerticalComponent for DerivedProjected --- src/iso19111/crs.cpp | 22 ++++++++++++++++++---- test/unit/test_crs.cpp | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index 2b94ba5f87..6f2c03275a 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -735,8 +735,7 @@ CRSNNPtr CRS::stripVerticalComponent() const { auto self = NN_NO_CHECK( std::dynamic_pointer_cast(shared_from_this().as_nullable())); - auto geogCRS = dynamic_cast(this); - if (geogCRS) { + if (auto geogCRS = dynamic_cast(this)) { const auto &axisList = geogCRS->coordinateSystem()->axisList(); if (axisList.size() == 3) { auto cs = cs::EllipsoidalCS::create(util::PropertyMap(), @@ -747,8 +746,8 @@ CRSNNPtr CRS::stripVerticalComponent() const { geogCRS->datum(), geogCRS->datumEnsemble(), cs)); } } - auto projCRS = dynamic_cast(this); - if (projCRS) { + + if (auto projCRS = dynamic_cast(this)) { const auto &axisList = projCRS->coordinateSystem()->axisList(); if (axisList.size() == 3) { auto cs = cs::CartesianCS::create(util::PropertyMap(), axisList[0], @@ -759,6 +758,21 @@ CRSNNPtr CRS::stripVerticalComponent() const { projCRS->baseCRS(), projCRS->derivingConversion(), cs)); } } + + if (auto derivedProjCRS = dynamic_cast(this)) { + const auto &axisList = derivedProjCRS->coordinateSystem()->axisList(); + if (axisList.size() == 3) { + auto cs = cs::CartesianCS::create(util::PropertyMap(), axisList[0], + axisList[1]); + return util::nn_static_pointer_cast( + DerivedProjectedCRS::create( + util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, + nameStr()), + derivedProjCRS->baseCRS(), + derivedProjCRS->derivingConversion(), cs)); + } + } + return self; } diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index e1ba07c1af..e61505a3cf 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -6452,6 +6452,20 @@ TEST(crs, crs_stripVerticalComponent) { ASSERT_TRUE(projCRS != nullptr); EXPECT_EQ(projCRS->coordinateSystem()->axisList().size(), 2U); } + + { + auto crs3D = + createDerivedProjectedCRS()->promoteTo3D(std::string(), nullptr); + auto derivedProj3D = + nn_dynamic_pointer_cast(crs3D); + ASSERT_TRUE(derivedProj3D != nullptr); + EXPECT_EQ(derivedProj3D->coordinateSystem()->axisList().size(), 3U); + + auto derivedProj2D = nn_dynamic_pointer_cast( + derivedProj3D->stripVerticalComponent()); + ASSERT_TRUE(derivedProj2D != nullptr); + EXPECT_EQ(derivedProj2D->coordinateSystem()->axisList().size(), 2U); + } } // ---------------------------------------------------------------------------