From 9697f59a0edb3650ece889abf209bb1abc1f51a0 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 8 Jan 2024 17:34:41 +0100 Subject: [PATCH] createOperationsCompoundToGeog(): tune selection logic when --grid-check known_available is specified --- .../operation/coordinateoperationfactory.cpp | 9 ++++--- test/unit/test_operationfactory.cpp | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/iso19111/operation/coordinateoperationfactory.cpp b/src/iso19111/operation/coordinateoperationfactory.cpp index 3cda6aad9e..473e1e48a8 100644 --- a/src/iso19111/operation/coordinateoperationfactory.cpp +++ b/src/iso19111/operation/coordinateoperationfactory.cpp @@ -5886,7 +5886,7 @@ void CoordinateOperationFactory::Private::createOperationsCompoundToGeog( } } } - if (!foundRegisteredTransformWithAllGridsAvailable && srcGeogCRS && + if (srcGeogCRS && !srcGeogCRS->_isEquivalentTo( geogDst, util::IComparable::Criterion::EQUIVALENT) && !srcGeogCRS->is2DPartOf3D(NN_NO_CHECK(geogDst), dbContext)) { @@ -5904,7 +5904,7 @@ void CoordinateOperationFactory::Private::createOperationsCompoundToGeog( componentsSrc[1], util::optional(), geogCRSTmp, util::optional(), context); bool foundRegisteredTransform = false; - foundRegisteredTransformWithAllGridsAvailable = false; + bool foundRegisteredTransformWithAllGridsAvailable2 = false; for (const auto &op : verticalTransformsTmp) { if (hasIdentifiers(op) && dbContext) { bool missingGrid = false; @@ -5923,13 +5923,14 @@ void CoordinateOperationFactory::Private::createOperationsCompoundToGeog( } foundRegisteredTransform = true; if (!missingGrid) { - foundRegisteredTransformWithAllGridsAvailable = + foundRegisteredTransformWithAllGridsAvailable2 = true; break; } } } - if (foundRegisteredTransformWithAllGridsAvailable) { + if (foundRegisteredTransformWithAllGridsAvailable2 && + !foundRegisteredTransformWithAllGridsAvailable) { verticalTransforms = std::move(verticalTransformsTmp); } else if (foundRegisteredTransform) { verticalTransforms.insert(verticalTransforms.end(), diff --git a/test/unit/test_operationfactory.cpp b/test/unit/test_operationfactory.cpp index 76f8aba63d..0b52a87b34 100644 --- a/test/unit/test_operationfactory.cpp +++ b/test/unit/test_operationfactory.cpp @@ -6942,6 +6942,31 @@ TEST(operation, compoundCRS_of_projCRS_to_geogCRS_3D_context) { // --------------------------------------------------------------------------- +TEST(operation, compoundCRS_to_geogCRS_3D_KNOWN_AVAILABLE_context) { + auto authFactory = + AuthorityFactory::create(DatabaseContext::create(), "EPSG"); + + auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); + ctxt->setGridAvailabilityUse( + CoordinateOperationContext::GridAvailabilityUse::KNOWN_AVAILABLE); + auto list = CoordinateOperationFactory::create()->createOperations( + authFactory->createCoordinateReferenceSystem( + "9537"), // RGAF09 + Martinique 1987 height + authFactory->createCoordinateReferenceSystem("4557"), // RRAF 1991 + ctxt); + ASSERT_GE(list.size(), 2U); + // Make sure that "RGAF09 to Martinique 1987 height (2)" (using RAMART2016) + // is listed first + EXPECT_EQ(list[0]->nameStr(), + "Inverse of RGAF09 to Martinique 1987 height (2) + " + "Inverse of RRAF 1991 to RGAF09 (1)"); + EXPECT_EQ(list[1]->nameStr(), + "Inverse of RRAF 1991 to RGAF09 (1) + " + "Inverse of RRAF 1991 to Martinique 1987 height (1)"); +} + +// --------------------------------------------------------------------------- + TEST(operation, compoundCRS_from_wkt_without_id_to_geogCRS) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG");