diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index 983ee1f9d8..0cd2f604b9 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -3706,6 +3706,10 @@ bool VerticalCRS::_isEquivalentTo( const util::IComparable *other, util::IComparable::Criterion criterion, const io::DatabaseContextPtr &dbContext) const { auto otherVertCRS = dynamic_cast(other); + if (otherVertCRS == nullptr || + !util::isOfExactType(*otherVertCRS)) { + return false; + } // TODO test geoidModel and velocityModel return otherVertCRS != nullptr && SingleCRS::baseIsEquivalentTo(other, criterion, dbContext); diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index e16ea308ad..cdccddd03f 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -5962,6 +5962,19 @@ TEST(crs, parametricCRS_WKT1) { // --------------------------------------------------------------------------- +TEST(crs, derivedVerticalCRS_basic) { + + auto crs = createDerivedVerticalCRS(); + EXPECT_TRUE(crs->isEquivalentTo(crs.get())); + EXPECT_TRUE(crs->shallowClone()->isEquivalentTo(crs.get())); + EXPECT_TRUE(!crs->isEquivalentTo(createUnrelatedObject().get())); + + EXPECT_FALSE(crs->isEquivalentTo(crs->baseCRS().get())); + EXPECT_FALSE(crs->baseCRS()->isEquivalentTo(crs.get())); +} + +// --------------------------------------------------------------------------- + TEST(crs, DerivedVerticalCRS_WKT2) { auto expected = "VERTCRS[\"Derived vertCRS\",\n" @@ -5976,10 +5989,6 @@ TEST(crs, DerivedVerticalCRS_WKT2) { " ID[\"EPSG\",9001]]]]"; auto crs = createDerivedVerticalCRS(); - EXPECT_TRUE(crs->isEquivalentTo(crs.get())); - EXPECT_TRUE(crs->shallowClone()->isEquivalentTo(crs.get())); - EXPECT_TRUE(!crs->isEquivalentTo(createUnrelatedObject().get())); - EXPECT_EQ(crs->exportToWKT( WKTFormatter::create(WKTFormatter::Convention::WKT2).get()), expected);