diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-02-25 15:31:41 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2020-02-25 16:32:08 +0100 |
| commit | 4dbb80b693aa547a7e1cca6df470392869ccdfff (patch) | |
| tree | 826c244aa812bfe820f073f086d70bf27259ac6d | |
| parent | 8a1f24dd37db128417a40de353a682bb825c4442 (diff) | |
| download | PROJ-4dbb80b693aa547a7e1cca6df470392869ccdfff.tar.gz PROJ-4dbb80b693aa547a7e1cca6df470392869ccdfff.zip | |
createOperations(): be robust to a GeographicCRS having a wrong ID attached to it (fixes #1982)
| -rw-r--r-- | src/iso19111/coordinateoperation.cpp | 23 | ||||
| -rw-r--r-- | test/unit/test_operation.cpp | 22 |
2 files changed, 42 insertions, 3 deletions
diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp index 4996001f..ea938e10 100644 --- a/src/iso19111/coordinateoperation.cpp +++ b/src/iso19111/coordinateoperation.cpp @@ -11489,11 +11489,30 @@ applyInverse(const std::vector<CoordinateOperationNNPtr> &list) { void CoordinateOperationFactory::Private::buildCRSIds( const crs::CRSNNPtr &crs, Private::Context &context, std::list<std::pair<std::string, std::string>> &ids) { + const auto &authFactory = context.context->getAuthorityFactory(); + assert(authFactory); for (const auto &id : crs->identifiers()) { const auto &authName = *(id->codeSpace()); const auto &code = id->code(); if (!authName.empty()) { - ids.emplace_back(authName, code); + const auto tmpAuthFactory = io::AuthorityFactory::create( + authFactory->databaseContext(), authName); + try { + // Consistency check for the ID attached to the object. + // See https://github.com/OSGeo/PROJ/issues/1982 where EPSG:4656 + // is attached to a GeographicCRS whereas it is a ProjectedCRS + if (tmpAuthFactory->createCoordinateReferenceSystem(code) + ->_isEquivalentTo( + crs.get(), + util::IComparable::Criterion:: + EQUIVALENT_EXCEPT_AXIS_ORDER_GEOGCRS)) { + ids.emplace_back(authName, code); + } else { + // TODO? log this inconsistency + } + } catch (const std::exception &) { + // TODO? log this inconsistency + } } } if (ids.empty()) { @@ -11521,8 +11540,6 @@ void CoordinateOperationFactory::Private::buildCRSIds( return; } - const auto &authFactory = context.context->getAuthorityFactory(); - assert(authFactory); const auto &authFactoryName = authFactory->getAuthority(); try { const auto tmpAuthFactory = io::AuthorityFactory::create( diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp index fdf81ebb..53b54808 100644 --- a/test/unit/test_operation.cpp +++ b/test/unit/test_operation.cpp @@ -4662,6 +4662,28 @@ TEST(operation, geogCRS_to_geogCRS_context_EPSG_4240_Indian1975_to_EPSG_4326) { // --------------------------------------------------------------------------- +TEST(operation, geogCRS_to_geogCRS_context_invalid_EPSG_ID) { + auto authFactory = + AuthorityFactory::create(DatabaseContext::create(), "EPSG"); + auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0); + // EPSG:4656 is incorrect. Should be EPSG:8997 + auto obj = WKTParser().createFromWKT( + "GEOGCS[\"ITRF2000\"," + "DATUM[\"International_Terrestrial_Reference_Frame_2000\"," + "SPHEROID[\"GRS 1980\",6378137,298.257222101," + "AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6656\"]]," + "PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]," + "AUTHORITY[\"EPSG\",\"4656\"]]"); + auto crs = nn_dynamic_pointer_cast<GeographicCRS>(obj); + ASSERT_TRUE(crs != nullptr); + + auto list = CoordinateOperationFactory::create()->createOperations( + NN_NO_CHECK(crs), GeographicCRS::EPSG_4326, ctxt); + ASSERT_EQ(list.size(), 1U); +} + +// --------------------------------------------------------------------------- + TEST(operation, vertCRS_to_geogCRS_context) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); |
