diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-02-24 15:40:25 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2020-02-25 00:19:19 +0100 |
| commit | 1ce2cc80a4a0ff248cda778ae16de51946fa61b7 (patch) | |
| tree | 8d0bda34e07d8637f6bc6c29c86400b6ce81c08c /test | |
| parent | 254bead44a3fe11a24418bf71813298aa2b386f1 (diff) | |
| download | PROJ-1ce2cc80a4a0ff248cda778ae16de51946fa61b7.tar.gz PROJ-1ce2cc80a4a0ff248cda778ae16de51946fa61b7.zip | |
CompoundCRS::create(): reject combinations of components not allowed by ISO 19111
Diffstat (limited to 'test')
| -rw-r--r-- | test/unit/test_crs.cpp | 66 | ||||
| -rw-r--r-- | test/unit/test_operation.cpp | 41 |
2 files changed, 69 insertions, 38 deletions
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<CRSNNPtr>{GeographicCRS::EPSG_4326, createVerticalCRS()}); + + // projected 2D + vertical + CompoundCRS::create( + PropertyMap(), + std::vector<CRSNNPtr>{createProjected(), createVerticalCRS()}); +} + +// --------------------------------------------------------------------------- + +TEST(crs, compoundCRS_invalid) { + EXPECT_THROW(CompoundCRS::create(PropertyMap(), {}), + InvalidCompoundCRSException); + + // Only one component + EXPECT_THROW(CompoundCRS::create(PropertyMap(), + std::vector<CRSNNPtr>{createProjected()}), + InvalidCompoundCRSException); + + // Two geographic + EXPECT_THROW( + CompoundCRS::create(PropertyMap(), + std::vector<CRSNNPtr>{GeographicCRS::EPSG_4326, + GeographicCRS::EPSG_4326}), + InvalidCompoundCRSException); + + // geographic 3D + vertical + EXPECT_THROW( + CompoundCRS::create(PropertyMap(), + std::vector<CRSNNPtr>{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<CRSNNPtr>{createProjected()}); - auto emptyCompoundCRS = - CompoundCRS::create(PropertyMap().set(IdentifiedObject::NAME_KEY, ""), - std::vector<CRSNNPtr>{}); - EXPECT_FALSE(compoundCRSOfProjCRS->isEquivalentTo(emptyCompoundCRS.get())); - auto compoundCRSOfGeogCRS = - CompoundCRS::create(PropertyMap().set(IdentifiedObject::NAME_KEY, ""), - std::vector<CRSNNPtr>{GeographicCRS::EPSG_4326}); - EXPECT_FALSE( - compoundCRSOfProjCRS->isEquivalentTo(compoundCRSOfGeogCRS.get())); + auto otherCompoundCRS = CompoundCRS::create( + PropertyMap().set(IdentifiedObject::NAME_KEY, ""), + std::vector<CRSNNPtr>{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<CRSNNPtr>{GeographicCRS::EPSG_4326}) - ->extractGeographicCRS(), - GeographicCRS::EPSG_4326); + EXPECT_EQ(CompoundCRS::create( + PropertyMap(), std::vector<CRSNNPtr>{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<double>()), InvalidOperation); - auto crsIn = CompoundCRS::create(PropertyMap(), std::vector<CRSNNPtr>{}); - EXPECT_THROW( - Transformation::createTOWGS84(crsIn, std::vector<double>(7, 0)), - InvalidOperation); + EXPECT_THROW(Transformation::createTOWGS84(createVerticalCRS(), + std::vector<double>(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( |
