From a16407e9d78ecb79c9d8920f9325652d9503a1c7 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 9 Mar 2022 11:42:09 +0100 Subject: Fix import of WKT of concatenated operation with inverse conversion of a compound CRS of a projected CRS (fixes #3076) --- src/iso19111/operation/concatenatedoperation.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/iso19111/operation/concatenatedoperation.cpp b/src/iso19111/operation/concatenatedoperation.cpp index 7da561b4..e5728c4c 100644 --- a/src/iso19111/operation/concatenatedoperation.cpp +++ b/src/iso19111/operation/concatenatedoperation.cpp @@ -276,14 +276,28 @@ void ConcatenatedOperation::fixStepsDirection( } } + const auto extractDerivedCRS = + [](const crs::CRS *crs) -> const crs::DerivedCRS * { + auto derivedCRS = dynamic_cast(crs); + if (derivedCRS) + return derivedCRS; + auto compoundCRS = dynamic_cast(crs); + if (compoundCRS) { + derivedCRS = dynamic_cast( + compoundCRS->componentReferenceSystems().front().get()); + if (derivedCRS) + return derivedCRS; + } + return nullptr; + }; + for (size_t i = 0; i < operationsInOut.size(); ++i) { auto &op = operationsInOut[i]; auto l_sourceCRS = op->sourceCRS(); auto l_targetCRS = op->targetCRS(); auto conv = dynamic_cast(op.get()); if (conv && i == 0 && !l_sourceCRS && !l_targetCRS) { - if (auto derivedCRS = dynamic_cast( - concatOpSourceCRS.get())) { + if (auto derivedCRS = extractDerivedCRS(concatOpSourceCRS.get())) { if (i + 1 < operationsInOut.size()) { // use the sourceCRS of the next operation as our target CRS l_targetCRS = operationsInOut[i + 1]->sourceCRS(); @@ -323,8 +337,7 @@ void ConcatenatedOperation::fixStepsDirection( } } else if (conv && i + 1 == operationsInOut.size() && !l_sourceCRS && !l_targetCRS) { - auto derivedCRS = - dynamic_cast(concatOpTargetCRS.get()); + auto derivedCRS = extractDerivedCRS(concatOpTargetCRS.get()); if (derivedCRS) { if (i >= 1) { // use the sourceCRS of the previous operation as our source @@ -350,8 +363,7 @@ void ConcatenatedOperation::fixStepsDirection( } else if (i >= 1) { l_sourceCRS = operationsInOut[i - 1]->targetCRS(); if (l_sourceCRS) { - derivedCRS = dynamic_cast( - l_sourceCRS.get()); + derivedCRS = extractDerivedCRS(l_sourceCRS.get()); if (derivedCRS && conv->isEquivalentTo( derivedCRS->derivingConversion().get(), -- cgit v1.2.3