From 5c79670110c114c720a9a9bad516f78eee59ea49 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 25 Feb 2020 15:31:41 +0100 Subject: createOperations(): be robust to a GeographicCRS having a wrong ID attached to it (fixes #1982) --- src/iso19111/coordinateoperation.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp index fef13e41..c97763e4 100644 --- a/src/iso19111/coordinateoperation.cpp +++ b/src/iso19111/coordinateoperation.cpp @@ -11687,11 +11687,30 @@ applyInverse(const std::vector &list) { void CoordinateOperationFactory::Private::buildCRSIds( const crs::CRSNNPtr &crs, Private::Context &context, std::list> &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()) { @@ -11719,8 +11738,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( -- cgit v1.2.3