Skip to content

Commit

Permalink
Merge pull request #3319 from jjimenezshaw/alterCSLinearUnit-derivedProj
Browse files Browse the repository at this point in the history
Implement alterCSLinearUnit for DerivedProjectedCRS
  • Loading branch information
rouault authored Sep 13, 2022
2 parents 137caf7 + 2e7501d commit 75a0a55
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/iso19111/crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ CRSNNPtr CRS::alterCSLinearUnit(const common::UnitOfMeasure &unit) const {
}
}

{
auto derivedProjCRS = dynamic_cast<const DerivedProjectedCRS *>(this);
if (derivedProjCRS) {
return DerivedProjectedCRS::create(
createPropertyMap(this), derivedProjCRS->baseCRS(),
derivedProjCRS->derivingConversion(),
derivedProjCRS->baseCRS()->coordinateSystem()->alterUnit(unit));
}
}

return NN_NO_CHECK(
std::dynamic_pointer_cast<CRS>(shared_from_this().as_nullable()));
}
Expand Down
13 changes: 13 additions & 0 deletions test/unit/test_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6484,6 +6484,19 @@ TEST(crs, crs_alterCSLinearUnit) {
EXPECT_EQ(cs->axisList()[1]->unit().conversionToSI(), 2);
}

{
auto crs = createDerivedProjectedCRS()->alterCSLinearUnit(
UnitOfMeasure("my unit", 2));
auto derivedProjCRS = dynamic_cast<DerivedProjectedCRS *>(crs.get());
ASSERT_TRUE(derivedProjCRS != nullptr);
auto cs = derivedProjCRS->coordinateSystem();
ASSERT_EQ(cs->axisList().size(), 2U);
EXPECT_EQ(cs->axisList()[0]->unit().name(), "my unit");
EXPECT_EQ(cs->axisList()[0]->unit().conversionToSI(), 2);
EXPECT_EQ(cs->axisList()[1]->unit().name(), "my unit");
EXPECT_EQ(cs->axisList()[1]->unit().conversionToSI(), 2);
}

{
auto crs = GeodeticCRS::EPSG_4978->alterCSLinearUnit(
UnitOfMeasure("my unit", 2));
Expand Down

0 comments on commit 75a0a55

Please sign in to comment.