Skip to content

Commit

Permalink
add implementation for alterGeodeticCRS for DerivedProjected
Browse files Browse the repository at this point in the history
  • Loading branch information
jjimenezshaw committed Nov 19, 2022
1 parent b4ead8c commit f048b28
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/iso19111/crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,27 @@ createPropertyMap(const common::IdentifiedObject *obj) {

//! @cond Doxygen_Suppress
CRSNNPtr CRS::alterGeodeticCRS(const GeodeticCRSNNPtr &newGeodCRS) const {
auto geodCRS = dynamic_cast<const GeodeticCRS *>(this);
if (geodCRS) {
if (dynamic_cast<const GeodeticCRS *>(this)) {
return newGeodCRS;
}

auto projCRS = dynamic_cast<const ProjectedCRS *>(this);
if (projCRS) {
if (auto projCRS = dynamic_cast<const ProjectedCRS *>(this)) {
return ProjectedCRS::create(createPropertyMap(this), newGeodCRS,
projCRS->derivingConversion(),
projCRS->coordinateSystem());
}

auto compoundCRS = dynamic_cast<const CompoundCRS *>(this);
if (compoundCRS) {
if (auto derivedProjCRS = dynamic_cast<const DerivedProjectedCRS *>(this)) {
auto newProjCRS =
NN_CHECK_ASSERT(util::nn_dynamic_pointer_cast<ProjectedCRS>(
derivedProjCRS->baseCRS()->alterGeodeticCRS(newGeodCRS)));

return DerivedProjectedCRS::create(createPropertyMap(this), newProjCRS,
derivedProjCRS->derivingConversion(),
derivedProjCRS->coordinateSystem());
}

if (auto compoundCRS = dynamic_cast<const CompoundCRS *>(this)) {
std::vector<CRSNNPtr> components;
for (const auto &subCrs : compoundCRS->componentReferenceSystems()) {
components.emplace_back(subCrs->alterGeodeticCRS(newGeodCRS));
Expand Down
9 changes: 9 additions & 0 deletions test/unit/test_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6488,6 +6488,15 @@ TEST(crs, crs_alterGeodeticCRS) {
createVerticalCRS()->alterGeodeticCRS(GeographicCRS::EPSG_4979);
EXPECT_TRUE(crs->isEquivalentTo(createVerticalCRS().get()));
}

{
auto crs = createDerivedProjectedCRS()->alterGeodeticCRS(
GeographicCRS::EPSG_4979);
auto derivedProjCRS = dynamic_cast<DerivedProjectedCRS *>(crs.get());
ASSERT_TRUE(derivedProjCRS != nullptr);
EXPECT_TRUE(derivedProjCRS->baseCRS()->baseCRS()->isEquivalentTo(
GeographicCRS::EPSG_4979.get()));
}
}

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

0 comments on commit f048b28

Please sign in to comment.