diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2021-09-28 14:47:10 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2021-09-28 14:47:10 +0200 |
| commit | 40ab72f2e9d913c7128fde24576183068dcd7ee2 (patch) | |
| tree | ecaabb15882203178135bbabe37bad860dcca772 | |
| parent | e6e6e4ca345e774910afa5bbe485c3d9f7851cd4 (diff) | |
| download | PROJ-40ab72f2e9d913c7128fde24576183068dcd7ee2.tar.gz PROJ-40ab72f2e9d913c7128fde24576183068dcd7ee2.zip | |
PROJStringFormatter: add optimizations useful for IAU CRS transformation pipelines
| -rw-r--r-- | src/iso19111/io.cpp | 26 | ||||
| -rw-r--r-- | test/unit/test_io.cpp | 20 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 9e7f0580..1f193559 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -7868,6 +7868,32 @@ const std::string &PROJStringFormatter::toString() const { continue; } + // axisswap order=2,-1 followed by axisswap order=-2,1 is a no-op + if (curStep.name == "axisswap" && prevStep.name == "axisswap" && + curStepParamCount == 1 && prevStepParamCount == 1 && + !prevStep.inverted && + prevStep.paramValues[0].equals("order", "2,-1") && + !curStep.inverted && + curStep.paramValues[0].equals("order", "-2,1")) { + deletePrevAndCurIter(); + continue; + } + + // axisswap order=2,-1 followed by axisswap order=1,-2 is + // equivalent to axisswap order=2,1 + if (curStep.name == "axisswap" && prevStep.name == "axisswap" && + curStepParamCount == 1 && prevStepParamCount == 1 && + !prevStep.inverted && + prevStep.paramValues[0].equals("order", "2,-1") && + !curStep.inverted && + curStep.paramValues[0].equals("order", "1,-2")) { + prevStep.inverted = false; + prevStep.paramValues[0] = Step::KeyValue("order", "2,1"); + // Delete this iter + iterCur = steps.erase(iterCur); + continue; + } + // axisswap order=2,1 followed by axisswap order=2,-1 is // equivalent to axisswap order=1,-2 // Same for axisswap order=-2,1 followed by axisswap order=2,1 diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 646a990a..4e888f2c 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -7881,6 +7881,26 @@ TEST(io, projstringformatter_axisswap_minus_two_one_followed_two_one) { // --------------------------------------------------------------------------- +TEST(io, projstringformatter_axisswap_two_minus_one_followed_minus_two_one) { + auto fmt = PROJStringFormatter::create(); + fmt->ingestPROJString("+proj=pipeline " + "+step +proj=axisswap +order=2,-1 " + "+step +proj=axisswap +order=-2,1"); + EXPECT_EQ(fmt->toString(), "+proj=noop"); +} + +// --------------------------------------------------------------------------- + +TEST(io, projstringformatter_axisswap_two_minus_one_followed_one_minus_two) { + auto fmt = PROJStringFormatter::create(); + fmt->ingestPROJString("+proj=pipeline " + "+step +proj=axisswap +order=2,-1 " + "+step +proj=axisswap +order=1,-2"); + EXPECT_EQ(fmt->toString(), "+proj=axisswap +order=2,1"); +} + +// --------------------------------------------------------------------------- + TEST(io, projstringformatter_unmodified) { const char *const strs[] = {"+proj=pipeline " "+step +proj=axisswap +order=2,-1 " |
