Skip to content

Commit

Permalink
add implementation for stripVerticalComponent for DerivedProjected
Browse files Browse the repository at this point in the history
  • Loading branch information
jjimenezshaw committed Nov 19, 2022
1 parent f048b28 commit 5f66a94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/iso19111/crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,7 @@ CRSNNPtr CRS::stripVerticalComponent() const {
auto self = NN_NO_CHECK(
std::dynamic_pointer_cast<CRS>(shared_from_this().as_nullable()));

auto geogCRS = dynamic_cast<const GeographicCRS *>(this);
if (geogCRS) {
if (auto geogCRS = dynamic_cast<const GeographicCRS *>(this)) {
const auto &axisList = geogCRS->coordinateSystem()->axisList();
if (axisList.size() == 3) {
auto cs = cs::EllipsoidalCS::create(util::PropertyMap(),
Expand All @@ -747,8 +746,8 @@ CRSNNPtr CRS::stripVerticalComponent() const {
geogCRS->datum(), geogCRS->datumEnsemble(), cs));
}
}
auto projCRS = dynamic_cast<const ProjectedCRS *>(this);
if (projCRS) {

if (auto projCRS = dynamic_cast<const ProjectedCRS *>(this)) {
const auto &axisList = projCRS->coordinateSystem()->axisList();
if (axisList.size() == 3) {
auto cs = cs::CartesianCS::create(util::PropertyMap(), axisList[0],
Expand All @@ -759,6 +758,21 @@ CRSNNPtr CRS::stripVerticalComponent() const {
projCRS->baseCRS(), projCRS->derivingConversion(), cs));
}
}

if (auto derivedProjCRS = dynamic_cast<const DerivedProjectedCRS *>(this)) {
const auto &axisList = derivedProjCRS->coordinateSystem()->axisList();
if (axisList.size() == 3) {
auto cs = cs::CartesianCS::create(util::PropertyMap(), axisList[0],
axisList[1]);
return util::nn_static_pointer_cast<CRS>(
DerivedProjectedCRS::create(
util::PropertyMap().set(common::IdentifiedObject::NAME_KEY,
nameStr()),
derivedProjCRS->baseCRS(),
derivedProjCRS->derivingConversion(), cs));
}
}

return self;
}

Expand Down
14 changes: 14 additions & 0 deletions test/unit/test_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6452,6 +6452,20 @@ TEST(crs, crs_stripVerticalComponent) {
ASSERT_TRUE(projCRS != nullptr);
EXPECT_EQ(projCRS->coordinateSystem()->axisList().size(), 2U);
}

{
auto crs3D =
createDerivedProjectedCRS()->promoteTo3D(std::string(), nullptr);
auto derivedProj3D =
nn_dynamic_pointer_cast<DerivedProjectedCRS>(crs3D);
ASSERT_TRUE(derivedProj3D != nullptr);
EXPECT_EQ(derivedProj3D->coordinateSystem()->axisList().size(), 3U);

auto derivedProj2D = nn_dynamic_pointer_cast<DerivedProjectedCRS>(
derivedProj3D->stripVerticalComponent());
ASSERT_TRUE(derivedProj2D != nullptr);
EXPECT_EQ(derivedProj2D->coordinateSystem()->axisList().size(), 2U);
}
}

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

0 comments on commit 5f66a94

Please sign in to comment.