Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement alterCSLinearUnit for CompoundCRS #3325

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the sake of completness, and test line 393 of crs.cpp, we'd need a test on a type of CRS that has no implementation of alterCSLinearUnit(). For example a temporal or parametric CRS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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