aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-08-20 19:54:59 +0200
committerGitHub <noreply@github.com>2021-08-20 19:54:59 +0200
commit34707b1ed5ddd89c8b1b4283321f5233d67d58f0 (patch)
tree39a4a426a6ee9ec518f7fd218e174251427df9dc /src
parentff682bff13392b35d718a3a64c55b3ea6762c9bc (diff)
parentc26bc402a4836a0d343c2afe7fd4a02c01e2d0d5 (diff)
downloadPROJ-34707b1ed5ddd89c8b1b4283321f5233d67d58f0.tar.gz
PROJ-34707b1ed5ddd89c8b1b4283321f5233d67d58f0.zip
Merge pull request #2819 from OSGeo/backport-2818-to-8.1
[Backport 8.1] ConcatenatedOperation::fixStepsDirection(): fix bad chaining of steps…
Diffstat (limited to 'src')
-rw-r--r--src/iso19111/io.cpp2
-rw-r--r--src/iso19111/operation/concatenatedoperation.cpp26
2 files changed, 24 insertions, 4 deletions
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp
index 867e08ed..c11fc5dc 100644
--- a/src/iso19111/io.cpp
+++ b/src/iso19111/io.cpp
@@ -7425,6 +7425,8 @@ const std::string &PROJStringFormatter::toString() const {
} else if (step.name == "pop" && step.inverted) {
step.name = "push";
step.inverted = false;
+ } else if (step.name == "noop" && d->steps_.size() > 1) {
+ iter = d->steps_.erase(iter);
} else {
++iter;
}
diff --git a/src/iso19111/operation/concatenatedoperation.cpp b/src/iso19111/operation/concatenatedoperation.cpp
index 20bbce6f..185ebb4a 100644
--- a/src/iso19111/operation/concatenatedoperation.cpp
+++ b/src/iso19111/operation/concatenatedoperation.cpp
@@ -335,13 +335,26 @@ void ConcatenatedOperation::fixStepsDirection(
}
}
} else if (conv && i > 0 && i < operationsInOut.size() - 1) {
- // For an intermediate conversion, use the target CRS of the
- // previous step and the source CRS of the next step
+
l_sourceCRS = operationsInOut[i - 1]->targetCRS();
l_targetCRS = operationsInOut[i + 1]->sourceCRS();
+ // For an intermediate conversion, use the target CRS of the
+ // previous step and the source CRS of the next step
if (l_sourceCRS && l_targetCRS) {
- op->setCRSs(NN_NO_CHECK(l_sourceCRS), NN_NO_CHECK(l_targetCRS),
- nullptr);
+ // If the sourceCRS is a projectedCRS and the target a
+ // geographic one, then we must inverse the operation. See
+ // https://github.com/OSGeo/PROJ/issues/2817
+ if (dynamic_cast<const crs::ProjectedCRS *>(
+ l_sourceCRS.get()) &&
+ dynamic_cast<const crs::GeographicCRS *>(
+ l_targetCRS.get())) {
+ op->setCRSs(NN_NO_CHECK(l_targetCRS),
+ NN_NO_CHECK(l_sourceCRS), nullptr);
+ op = op->inverse();
+ } else {
+ op->setCRSs(NN_NO_CHECK(l_sourceCRS),
+ NN_NO_CHECK(l_targetCRS), nullptr);
+ }
} else if (l_sourceCRS && l_targetCRS == nullptr &&
conv->method()->getEPSGCode() ==
EPSG_CODE_METHOD_HEIGHT_DEPTH_REVERSAL) {
@@ -380,6 +393,11 @@ void ConcatenatedOperation::fixStepsDirection(
// whereas we should instead use the reverse path.
auto prevOpTarget = (i == 0) ? concatOpSourceCRS.as_nullable()
: operationsInOut[i - 1]->targetCRS();
+ if (prevOpTarget == nullptr) {
+ throw InvalidOperation(
+ "Cannot determine targetCRS of operation at step " +
+ toString(static_cast<int>(i)));
+ }
if (compareStepCRS(l_sourceCRS.get(), prevOpTarget.get())) {
// do nothing
} else if (compareStepCRS(l_targetCRS.get(), prevOpTarget.get())) {