From a48a69e1923dfb18a95a477a89d1d4c4a0adde47 Mon Sep 17 00:00:00 2001 From: Javier Jimenez Shaw Date: Wed, 14 Sep 2022 23:50:09 +0200 Subject: [PATCH] implement alterCSLinearUnit for CompoundCRS --- src/iso19111/crs.cpp | 12 ++++++++++++ test/unit/test_crs.cpp | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index 983ee1f9d8..5bb99969f8 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -378,6 +378,18 @@ CRSNNPtr CRS::alterCSLinearUnit(const common::UnitOfMeasure &unit) const { } } + { + auto compoundCRS = dynamic_cast(this); + if (compoundCRS) { + std::vector components; + for (const auto &subCrs : + compoundCRS->componentReferenceSystems()) { + components.push_back(subCrs->alterCSLinearUnit(unit)); + } + return CompoundCRS::create(createPropertyMap(this), components); + } + } + return NN_NO_CHECK( std::dynamic_pointer_cast(shared_from_this().as_nullable())); } diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index 7928270858..f38fe3c657 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -6551,11 +6551,25 @@ TEST(crs, crs_alterCSLinearUnit) { } { - // Not implemented on compoundCRS auto crs = createCompoundCRS()->alterCSLinearUnit(UnitOfMeasure("my unit", 2)); - EXPECT_TRUE(createCompoundCRS()->isEquivalentTo(crs.get())); + auto compoundCRS = dynamic_cast(crs.get()); + ASSERT_TRUE(compoundCRS != nullptr); + EXPECT_EQ(compoundCRS->componentReferenceSystems().size(), 2U); + for (const auto &subCrs : compoundCRS->componentReferenceSystems()) { + auto singleCrs = dynamic_cast(subCrs.get()); + ASSERT_TRUE(singleCrs != nullptr); + auto cs = singleCrs->coordinateSystem(); + ASSERT_GE(cs->axisList().size(), 1U); + EXPECT_EQ(cs->axisList()[0]->unit().name(), "my unit"); + EXPECT_EQ(cs->axisList()[0]->unit().conversionToSI(), 2); + } } + + // Not implemented on parametricCRS + auto crs = + createParametricCRS()->alterCSLinearUnit(UnitOfMeasure("my unit", 2)); + EXPECT_TRUE(createParametricCRS()->isEquivalentTo(crs.get())); } // ---------------------------------------------------------------------------