From f28d36cee9ec099ae5fea3873988204a7ebda520 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 6 Oct 2021 19:26:09 +0200 Subject: CRS::_isEquivalentTo(): be tolerant to different order of PROJ step options (fixes #2886) --- src/iso19111/io.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/iso19111/io.cpp') diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 1f193559..24201ee1 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -7436,6 +7436,7 @@ struct PROJStringFormatter::Private { bool crsExport_ = false; bool legacyCRSToCRSContext_ = false; bool multiLine_ = false; + bool normalizeOutput_ = false; int indentWidth_ = 2; int indentLevel_ = 0; int maxLineLength_ = 80; @@ -7535,6 +7536,17 @@ const std::string &PROJStringFormatter::toString() const { d->result_.clear(); auto &steps = d->steps_; + + if (d->normalizeOutput_) { + // Sort +key=value options of each step in lexicographic order. + for (auto &step : steps) { + std::sort(step.paramValues.begin(), step.paramValues.end(), + [](const Step::KeyValue &a, const Step::KeyValue &b) { + return a.key < b.key; + }); + } + } + for (auto iter = steps.begin(); iter != steps.end();) { // Remove no-op helmert auto &step = *iter; @@ -8689,6 +8701,19 @@ bool PROJStringFormatter::getLegacyCRSToCRSContext() const { // --------------------------------------------------------------------------- +/** Asks for a "normalized" output during toString(), aimed at comparing two + * strings for equivalence. + * + * This consists for now in sorting the +key=value option in lexicographic + * order. + */ +PROJStringFormatter &PROJStringFormatter::setNormalizeOutput() { + d->normalizeOutput_ = true; + return *this; +} + +// --------------------------------------------------------------------------- + const DatabaseContextPtr &PROJStringFormatter::databaseContext() const { return d->dbContext_; } -- cgit v1.2.3