Skip to content

Commit

Permalink
Merge pull request #3325 from jjimenezshaw/alterCSLinearUnit-compound
Browse files Browse the repository at this point in the history
implement alterCSLinearUnit for CompoundCRS
  • Loading branch information
rouault authored Sep 15, 2022
2 parents b674a2f + a48a69e commit cb29e99
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/iso19111/crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@ CRSNNPtr CRS::alterCSLinearUnit(const common::UnitOfMeasure &unit) const {
}
}

{
auto compoundCRS = dynamic_cast<const CompoundCRS *>(this);
if (compoundCRS) {
std::vector<CRSNNPtr> 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<CRS>(shared_from_this().as_nullable()));
}
Expand Down
18 changes: 16 additions & 2 deletions test/unit/test_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompoundCRS *>(crs.get());
ASSERT_TRUE(compoundCRS != nullptr);
EXPECT_EQ(compoundCRS->componentReferenceSystems().size(), 2U);
for (const auto &subCrs : compoundCRS->componentReferenceSystems()) {
auto singleCrs = dynamic_cast<SingleCRS *>(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()));
}

// ---------------------------------------------------------------------------
Expand Down

0 comments on commit cb29e99

Please sign in to comment.