diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-12-28 16:44:28 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-12-28 16:44:28 +0100 |
| commit | f49a5b744a28fe2a51cdcb7b4bc86f5d834f1e54 (patch) | |
| tree | 2e995db7ec543eb29680825d12d9ff244afb888d /src | |
| parent | 9660576bf3be57c196325ebd8de417984b7160b1 (diff) | |
| download | PROJ-f49a5b744a28fe2a51cdcb7b4bc86f5d834f1e54.tar.gz PROJ-f49a5b744a28fe2a51cdcb7b4bc86f5d834f1e54.zip | |
importFromWKT: better deal with axis of the baseCRS of a projected CRS
Diffstat (limited to 'src')
| -rw-r--r-- | src/iso19111/io.cpp | 53 | ||||
| -rw-r--r-- | src/iso19111/util.cpp | 11 |
2 files changed, 55 insertions, 9 deletions
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 6175c415..effb3968 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -1149,7 +1149,7 @@ struct WKTParser::Private { Private(const Private &) = delete; Private &operator=(const Private &) = delete; - void emitRecoverableAssertion(const std::string &errorMsg); + void emitRecoverableWarning(const std::string &errorMsg); BaseObjectNNPtr build(const WKTNodeNNPtr &node); @@ -1331,7 +1331,7 @@ std::list<std::string> WKTParser::warningList() const { // --------------------------------------------------------------------------- //! @cond Doxygen_Suppress -void WKTParser::Private::emitRecoverableAssertion(const std::string &errorMsg) { +void WKTParser::Private::emitRecoverableWarning(const std::string &errorMsg) { if (strict_) { throw ParsingException(errorMsg); } else { @@ -1688,8 +1688,8 @@ UnitOfMeasure WKTParser::Private::buildUnit(const WKTNodeNNPtr &node, auto &idNode = nodeP->lookForChild(WKTConstants::ID, WKTConstants::AUTHORITY); if (!isNull(idNode) && idNode->GP()->childrenSize() < 2) { - emitRecoverableAssertion("not enough children in " + - idNode->GP()->value() + " node"); + emitRecoverableWarning("not enough children in " + + idNode->GP()->value() + " node"); } const bool hasValidIdNode = !isNull(idNode) && idNode->GP()->childrenSize() >= 2; @@ -2553,7 +2553,7 @@ WKTParser::Private::buildGeodeticCRS(const WKTNodeNNPtr &node) { // PRIMEM is required in WKT1 if (ci_equal(nodeName, WKTConstants::GEOGCS) || ci_equal(nodeName, WKTConstants::GEOCCS)) { - emitRecoverableAssertion(nodeName + " should have a PRIMEM node"); + emitRecoverableWarning(nodeName + " should have a PRIMEM node"); } } @@ -2596,8 +2596,43 @@ WKTParser::Private::buildGeodeticCRS(const WKTNodeNNPtr &node) { if (ellipsoidalCS) { assert(!ci_equal(nodeName, WKTConstants::GEOCCS)); try { - return GeographicCRS::create(props, datum, datumEnsemble, - NN_NO_CHECK(ellipsoidalCS)); + auto crs = GeographicCRS::create(props, datum, datumEnsemble, + NN_NO_CHECK(ellipsoidalCS)); + // In case of missing CS node, or to check it, query the coordinate + // system from the DB if possible (typically for the baseCRS of a + // ProjectedCRS) + if (!crs->identifiers().empty() && dbContext_) { + GeographicCRSPtr dbCRS; + try { + const auto &id = crs->identifiers()[0]; + auto authFactory = AuthorityFactory::create( + NN_NO_CHECK(dbContext_), *id->codeSpace()); + dbCRS = authFactory->createGeographicCRS(id->code()) + .as_nullable(); + } catch (const util::Exception &) { + } + if (dbCRS && + (!isNull(csNode) || + node->countChildrenOfName(WKTConstants::AXIS) != 0) && + !ellipsoidalCS->_isEquivalentTo( + dbCRS->coordinateSystem().get(), + util::IComparable::Criterion::EQUIVALENT)) { + emitRecoverableWarning( + "Coordinate system of GeographicCRS in the WKT " + "definition is different from the one of the " + "authority. Unsetting the identifier to avoid " + "confusion"); + props.unset(Identifier::CODESPACE_KEY); + props.unset(Identifier::AUTHORITY_KEY); + props.unset(IdentifiedObject::IDENTIFIERS_KEY); + crs = GeographicCRS::create(props, datum, datumEnsemble, + NN_NO_CHECK(ellipsoidalCS)); + } else if (dbCRS) { + crs = GeographicCRS::create(props, datum, datumEnsemble, + dbCRS->coordinateSystem()); + } + } + return crs; } catch (const util::Exception &e) { throw ParsingException(std::string("buildGeodeticCRS: ") + e.what()); @@ -4376,13 +4411,13 @@ BaseObjectNNPtr WKTParser::createFromWKT(const std::string &wkt) { dialect == WKTGuessedDialect::WKT1_ESRI) { auto errorMsg = pj_wkt1_parse(wkt); if (!errorMsg.empty()) { - d->emitRecoverableAssertion(errorMsg); + d->emitRecoverableWarning(errorMsg); } } else if (dialect == WKTGuessedDialect::WKT2_2015 || dialect == WKTGuessedDialect::WKT2_2018) { auto errorMsg = pj_wkt2_parse(wkt); if (!errorMsg.empty()) { - d->emitRecoverableAssertion(errorMsg); + d->emitRecoverableWarning(errorMsg); } } diff --git a/src/iso19111/util.cpp b/src/iso19111/util.cpp index ac6357a2..b8c6c439 100644 --- a/src/iso19111/util.cpp +++ b/src/iso19111/util.cpp @@ -282,6 +282,17 @@ const BaseObjectNNPtr *PropertyMap::get(const std::string &key) const { } return nullptr; } +// --------------------------------------------------------------------------- + +//! @cond Doxygen_Suppress +void PropertyMap::unset(const std::string &key) { + for (auto iter = d->list_.begin(); iter != d->list_.end(); ++iter) { + if (iter->first == key) { + d->list_.erase(iter); + return; + } + } +} //! @endcond // --------------------------------------------------------------------------- |
