From 1ce2cc80a4a0ff248cda778ae16de51946fa61b7 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 24 Feb 2020 15:40:25 +0100 Subject: CompoundCRS::create(): reject combinations of components not allowed by ISO 19111 --- test/unit/test_crs.cpp | 66 ++++++++++++++++++++++++++++++++------------ test/unit/test_operation.cpp | 41 ++++++++++++++------------- 2 files changed, 69 insertions(+), 38 deletions(-) (limited to 'test') diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index 542d1226..c988080b 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -3331,6 +3331,46 @@ static CompoundCRSNNPtr createCompoundCRS() { // --------------------------------------------------------------------------- +TEST(crs, compoundCRS_valid) { + // geographic 2D + vertical + CompoundCRS::create( + PropertyMap(), + std::vector{GeographicCRS::EPSG_4326, createVerticalCRS()}); + + // projected 2D + vertical + CompoundCRS::create( + PropertyMap(), + std::vector{createProjected(), createVerticalCRS()}); +} + +// --------------------------------------------------------------------------- + +TEST(crs, compoundCRS_invalid) { + EXPECT_THROW(CompoundCRS::create(PropertyMap(), {}), + InvalidCompoundCRSException); + + // Only one component + EXPECT_THROW(CompoundCRS::create(PropertyMap(), + std::vector{createProjected()}), + InvalidCompoundCRSException); + + // Two geographic + EXPECT_THROW( + CompoundCRS::create(PropertyMap(), + std::vector{GeographicCRS::EPSG_4326, + GeographicCRS::EPSG_4326}), + InvalidCompoundCRSException); + + // geographic 3D + vertical + EXPECT_THROW( + CompoundCRS::create(PropertyMap(), + std::vector{GeographicCRS::EPSG_4979, + createVerticalCRS()}), + InvalidCompoundCRSException); +} + +// --------------------------------------------------------------------------- + TEST(crs, compoundCRS_as_WKT2) { auto crs = createCompoundCRS(); auto expected = @@ -3385,18 +3425,10 @@ TEST(crs, compoundCRS_isEquivalentTo) { EXPECT_TRUE(crs->isEquivalentTo(crs.get())); EXPECT_TRUE(crs->shallowClone()->isEquivalentTo(crs.get())); EXPECT_FALSE(crs->isEquivalentTo(createUnrelatedObject().get())); - auto compoundCRSOfProjCRS = - CompoundCRS::create(PropertyMap().set(IdentifiedObject::NAME_KEY, ""), - std::vector{createProjected()}); - auto emptyCompoundCRS = - CompoundCRS::create(PropertyMap().set(IdentifiedObject::NAME_KEY, ""), - std::vector{}); - EXPECT_FALSE(compoundCRSOfProjCRS->isEquivalentTo(emptyCompoundCRS.get())); - auto compoundCRSOfGeogCRS = - CompoundCRS::create(PropertyMap().set(IdentifiedObject::NAME_KEY, ""), - std::vector{GeographicCRS::EPSG_4326}); - EXPECT_FALSE( - compoundCRSOfProjCRS->isEquivalentTo(compoundCRSOfGeogCRS.get())); + auto otherCompoundCRS = CompoundCRS::create( + PropertyMap().set(IdentifiedObject::NAME_KEY, ""), + std::vector{GeographicCRS::EPSG_4326, createVerticalCRS()}); + EXPECT_FALSE(crs->isEquivalentTo(otherCompoundCRS.get())); } // --------------------------------------------------------------------------- @@ -4154,11 +4186,11 @@ TEST(crs, extractGeographicCRS) { GeographicCRS::EPSG_4326); EXPECT_EQ(createProjected()->extractGeographicCRS(), GeographicCRS::EPSG_4326); - EXPECT_EQ( - CompoundCRS::create(PropertyMap(), - std::vector{GeographicCRS::EPSG_4326}) - ->extractGeographicCRS(), - GeographicCRS::EPSG_4326); + EXPECT_EQ(CompoundCRS::create( + PropertyMap(), std::vector{GeographicCRS::EPSG_4326, + createVerticalCRS()}) + ->extractGeographicCRS(), + GeographicCRS::EPSG_4326); } // --------------------------------------------------------------------------- diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp index 63ed97e7..1af41fde 100644 --- a/test/unit/test_operation.cpp +++ b/test/unit/test_operation.cpp @@ -1142,16 +1142,32 @@ TEST(operation, transformation_inverse) { // --------------------------------------------------------------------------- +static VerticalCRSNNPtr createVerticalCRS() { + PropertyMap propertiesVDatum; + propertiesVDatum.set(Identifier::CODESPACE_KEY, "EPSG") + .set(Identifier::CODE_KEY, 5101) + .set(IdentifiedObject::NAME_KEY, "Ordnance Datum Newlyn"); + auto vdatum = VerticalReferenceFrame::create(propertiesVDatum); + PropertyMap propertiesCRS; + propertiesCRS.set(Identifier::CODESPACE_KEY, "EPSG") + .set(Identifier::CODE_KEY, 5701) + .set(IdentifiedObject::NAME_KEY, "ODN height"); + return VerticalCRS::create( + propertiesCRS, vdatum, + VerticalCS::createGravityRelatedHeight(UnitOfMeasure::METRE)); +} + +// --------------------------------------------------------------------------- + TEST(operation, transformation_createTOWGS84) { EXPECT_THROW(Transformation::createTOWGS84(GeographicCRS::EPSG_4326, std::vector()), InvalidOperation); - auto crsIn = CompoundCRS::create(PropertyMap(), std::vector{}); - EXPECT_THROW( - Transformation::createTOWGS84(crsIn, std::vector(7, 0)), - InvalidOperation); + EXPECT_THROW(Transformation::createTOWGS84(createVerticalCRS(), + std::vector(7, 0)), + InvalidOperation); } // --------------------------------------------------------------------------- @@ -6563,23 +6579,6 @@ TEST(operation, WGS84_G1762_to_compoundCRS_with_bound_vertCRS) { // --------------------------------------------------------------------------- -static VerticalCRSNNPtr createVerticalCRS() { - PropertyMap propertiesVDatum; - propertiesVDatum.set(Identifier::CODESPACE_KEY, "EPSG") - .set(Identifier::CODE_KEY, 5101) - .set(IdentifiedObject::NAME_KEY, "Ordnance Datum Newlyn"); - auto vdatum = VerticalReferenceFrame::create(propertiesVDatum); - PropertyMap propertiesCRS; - propertiesCRS.set(Identifier::CODESPACE_KEY, "EPSG") - .set(Identifier::CODE_KEY, 5701) - .set(IdentifiedObject::NAME_KEY, "ODN height"); - return VerticalCRS::create( - propertiesCRS, vdatum, - VerticalCS::createGravityRelatedHeight(UnitOfMeasure::METRE)); -} - -// --------------------------------------------------------------------------- - TEST(operation, compoundCRS_to_geogCRS) { auto compound = CompoundCRS::create( -- cgit v1.2.3