diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-11-26 14:11:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-26 14:11:50 +0100 |
| commit | aeaf21ecae5296adf81ed2cab72ec07b919abf87 (patch) | |
| tree | 45eff36135b1045a5b8ccbbc68bce42437e373fe /src/iso19111/io.cpp | |
| parent | f764bd8a970ce6d40da3203d4d0af6c8d5d2f762 (diff) | |
| parent | 49c15bc4a08c1b302bfbd509b2588dd80142de31 (diff) | |
| download | PROJ-aeaf21ecae5296adf81ed2cab72ec07b919abf87.tar.gz PROJ-aeaf21ecae5296adf81ed2cab72ec07b919abf87.zip | |
Merge pull request #1748 from rouault/improve_hgrid_vgrid_hgrid_inv_take2
Optimize pipelines involving horizontal shift grid, vertical shift grid, inverse horizontal shift grid (take 2)
Diffstat (limited to 'src/iso19111/io.cpp')
| -rw-r--r-- | src/iso19111/io.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 678c5d98..0d98e2de 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -6278,12 +6278,25 @@ struct Step { return key == otherKey && value == otherVal; } + bool operator==(const KeyValue &other) const noexcept { + return key == other.key && value == other.value; + } + bool operator!=(const KeyValue &other) const noexcept { return key != other.key || value != other.value; } }; std::vector<KeyValue> paramValues{}; + + bool hasKey(const char *keyName) const { + for (const auto &kv : paramValues) { + if (kv.key == keyName) { + return true; + } + } + return false; + } }; Step::KeyValue::KeyValue(const char *keyIn, const std::string &valueIn) @@ -6790,6 +6803,46 @@ const std::string &PROJStringFormatter::toString() const { } } + // +step +proj=hgridshift +grids=grid_A + // +step +proj=vgridshift [...] <== curStep + // +step +inv +proj=hgridshift +grids=grid_A + // ==> + // +step +proj=push +v_1 +v_2 + // +step +proj=hgridshift +grids=grid_A +omit_inv + // +step +proj=vgridshift [...] + // +step +inv +proj=hgridshift +grids=grid_A +omit_fwd + // +step +proj=pop +v_1 +v_2 + if (i + 1 < d->steps_.size() && prevStep.name == "hgridshift" && + prevStepParamCount == 1 && curStep.name == "vgridshift") { + auto iterNext = iterCur; + ++iterNext; + auto &nextStep = *iterNext; + if (nextStep.name == "hgridshift" && + nextStep.inverted != prevStep.inverted && + nextStep.paramValues.size() == 1 && + prevStep.paramValues[0] == nextStep.paramValues[0]) { + Step pushStep; + pushStep.name = "push"; + pushStep.paramValues.emplace_back("v_1"); + pushStep.paramValues.emplace_back("v_2"); + d->steps_.insert(iterPrev, pushStep); + + prevStep.paramValues.emplace_back("omit_inv"); + + nextStep.paramValues.emplace_back("omit_fwd"); + + Step popStep; + popStep.name = "pop"; + popStep.paramValues.emplace_back("v_1"); + popStep.paramValues.emplace_back("v_2"); + ++iterNext; + d->steps_.insert(iterNext, popStep); + + changeDone = true; + break; + } + } + // detect a step and its inverse if (curStep.inverted != prevStep.inverted && curStep.name == prevStep.name && @@ -6813,7 +6866,9 @@ const std::string &PROJStringFormatter::toString() const { if (d->steps_.size() > 1 || (d->steps_.size() == 1 && - (d->steps_.front().inverted || !d->globalParamValues_.empty()))) { + (d->steps_.front().inverted || d->steps_.front().hasKey("omit_inv") || + d->steps_.front().hasKey("omit_fwd") || + !d->globalParamValues_.empty()))) { d->appendToResult("+proj=pipeline"); for (const auto ¶mValue : d->globalParamValues_) { |
