Skip to content

Commit

Permalink
createOperations(): be robust to a GeographicCRS having a wrong ID at…
Browse files Browse the repository at this point in the history
…tached to it (fixes #1982)
  • Loading branch information
rouault committed Feb 25, 2020
1 parent ca8dd84 commit 6cb4a50
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/iso19111/coordinateoperation.cpp
Expand Up @@ -11687,11 +11687,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()) {
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 22 additions & 0 deletions test/unit/test_operation.cpp
Expand Up @@ -4761,6 +4761,28 @@ TEST(operation, geogCRS_to_geogCRS_context_helmert_geog3D_to_geocentirc) {

// ---------------------------------------------------------------------------

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");
Expand Down

0 comments on commit 6cb4a50

Please sign in to comment.