Skip to content

Commit

Permalink
Merge pull request #3342 from rouault/fix_3340
Browse files Browse the repository at this point in the history
WKT import: 3D-promote base CRS of 3D DerivedProjectedCRS (fixes #3340)
  • Loading branch information
rouault authored and github-actions[bot] committed Sep 25, 2022
1 parent dde3af1 commit a6897da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5145,6 +5145,13 @@ WKTParser::Private::buildDerivedProjectedCRS(const WKTNodeNNPtr &node) {
ThrowMissing(WKTConstants::CS_);
}
auto cs = buildCS(csNode, node, UnitOfMeasure::NONE);

if (cs->axisList().size() == 3 &&
baseProjCRS->coordinateSystem()->axisList().size() == 2) {
baseProjCRS = NN_NO_CHECK(util::nn_dynamic_pointer_cast<ProjectedCRS>(
baseProjCRS->promoteTo3D(std::string(), dbContext_)));
}

return DerivedProjectedCRS::create(buildProperties(node), baseProjCRS,
conversion, cs);
}
Expand Down
15 changes: 15 additions & 0 deletions test/unit/test_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6821,6 +6821,21 @@ TEST(crs, promoteTo3D_and_demoteTo2D) {
EXPECT_TRUE(crs3DAsDerivedProj->promoteTo3D(std::string(), nullptr)
->isEquivalentTo(crs3DAsDerivedProj.get()));

// Check that importing an exported DerivedProjected 3D CRS as WKT keeps
// the 3D aspect of the baseCRS (see #3340)
{
WKTFormatterNNPtr f(
WKTFormatter::create(WKTFormatter::Convention::WKT2_2019));
crs3DAsDerivedProj->exportToWKT(f.get());
auto obj = WKTParser().createFromWKT(f->toString());
auto crsFromWkt = nn_dynamic_pointer_cast<DerivedProjectedCRS>(obj);
ASSERT_TRUE(crsFromWkt != nullptr);
EXPECT_EQ(crsFromWkt->coordinateSystem()->axisList().size(), 3U);
EXPECT_EQ(
crsFromWkt->baseCRS()->coordinateSystem()->axisList().size(),
3U);
}

auto demoted = crs3DAsDerivedProj->demoteTo2D(std::string(), dbContext);
EXPECT_EQ(demoted->baseCRS()->coordinateSystem()->axisList().size(),
2U);
Expand Down

0 comments on commit a6897da

Please sign in to comment.