diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2021-10-06 19:26:09 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2021-10-06 19:26:09 +0200 |
| commit | f28d36cee9ec099ae5fea3873988204a7ebda520 (patch) | |
| tree | 9adde1d0f8936b3439bb2b42e5c075f9d8df6362 /src/iso19111/crs.cpp | |
| parent | 3a67ea87fac5b835df7966fa801881eaf7503e78 (diff) | |
| download | PROJ-f28d36cee9ec099ae5fea3873988204a7ebda520.tar.gz PROJ-f28d36cee9ec099ae5fea3873988204a7ebda520.zip | |
CRS::_isEquivalentTo(): be tolerant to different order of PROJ step options (fixes #2886)
Diffstat (limited to 'src/iso19111/crs.cpp')
| -rw-r--r-- | src/iso19111/crs.cpp | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index 731bf7f9..b7d57767 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -1394,6 +1394,7 @@ bool SingleCRS::baseIsEquivalentTo( return false; } + // Check datum if (criterion == util::IComparable::Criterion::STRICT) { const auto &thisDatum = d->datum; const auto &otherDatum = otherSingleCRS->d->datum; @@ -1428,10 +1429,36 @@ bool SingleCRS::baseIsEquivalentTo( } } - return d->coordinateSystem->_isEquivalentTo( - otherSingleCRS->d->coordinateSystem.get(), criterion, - dbContext) && - getExtensionProj4() == otherSingleCRS->getExtensionProj4(); + // Check coordinate system + if (!(d->coordinateSystem->_isEquivalentTo( + otherSingleCRS->d->coordinateSystem.get(), criterion, dbContext))) { + return false; + } + + // Now compare PROJ4 extensions + + const auto &thisProj4 = getExtensionProj4(); + const auto &otherProj4 = otherSingleCRS->getExtensionProj4(); + + if (thisProj4.empty() && otherProj4.empty()) { + return true; + } + + if (!(thisProj4.empty() ^ otherProj4.empty())) { + return true; + } + + // Asks for a "normalized" output during toString(), aimed at comparing two + // strings for equivalence. + auto formatter1 = io::PROJStringFormatter::create(); + formatter1->setNormalizeOutput(); + formatter1->ingestPROJString(thisProj4); + + auto formatter2 = io::PROJStringFormatter::create(); + formatter2->setNormalizeOutput(); + formatter2->ingestPROJString(otherProj4); + + return formatter1->toString() == formatter2->toString(); } // --------------------------------------------------------------------------- |
