diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-12-16 16:05:38 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-12-17 20:01:05 +0100 |
| commit | dcb58eb624f87fad1362bfc593b274f84fa44889 (patch) | |
| tree | ed148e4a19f507722383467264bbd02417b7c64a /src/io.cpp | |
| parent | a44a6231364d893d906711138035074fb95521a2 (diff) | |
| download | PROJ-dcb58eb624f87fad1362bfc593b274f84fa44889.tar.gz PROJ-dcb58eb624f87fad1362bfc593b274f84fa44889.zip | |
Add WKT1 grammar validation; change prototype of proj_obj_create_from_wkt()
Diffstat (limited to 'src/io.cpp')
| -rw-r--r-- | src/io.cpp | 35 |
1 files changed, 30 insertions, 5 deletions
@@ -60,6 +60,8 @@ #include "proj_constants.h" +#include "pj_wkt1_parser.h" + // PROJ include order is sensitive // clang-format off #include "proj.h" @@ -1125,7 +1127,7 @@ std::string WKTNode::toString() const { //! @cond Doxygen_Suppress struct WKTParser::Private { bool strict_ = true; - std::vector<std::string> warningList_{}; + std::list<std::string> warningList_{}; std::vector<double> toWGS84Parameters_{}; std::string datumPROJ4Grids_{}; bool esriStyle_ = false; @@ -1321,7 +1323,7 @@ WKTParser &WKTParser::setStrict(bool strict) { * * \note The list might be non-empty only is setStrict(false) has been called. */ -std::vector<std::string> WKTParser::warningList() const { +std::list<std::string> WKTParser::warningList() const { return d->warningList_; } @@ -4205,8 +4207,10 @@ BaseObjectNNPtr createFromUserInput(const std::string &text, for (const auto &wktConstants : WKTConstants::constants()) { if (ci_starts_with(text, wktConstants)) { - return WKTParser().attachDatabaseContext(dbContext).createFromWKT( - text); + return WKTParser() + .attachDatabaseContext(dbContext) + .setStrict(false) + .createFromWKT(text); } } const char *textWithoutPlusPrefix = text.c_str(); @@ -4339,11 +4343,32 @@ BaseObjectNNPtr createFromUserInput(const std::string &text, // --------------------------------------------------------------------------- /** \brief Instanciate a sub-class of BaseObject from a WKT string. + * + * By default, validation is strict (to the extent of the checks that are + * actually implemented. Currently only WKT1 strict grammar is checked), and + * any issue detected will cause an exception to be thrown, unless + * setStrict(false) is called priorly. + * + * In non-strict mode, non-fatal issues will be recovered and simply listed + * in warningList(). This does not prevent more severe errors to cause an + * exception to be thrown. + * * @throw ParsingException */ BaseObjectNNPtr WKTParser::createFromWKT(const std::string &wkt) { WKTNodeNNPtr root = WKTNode::createFrom(wkt); - return d->build(root); + auto obj = d->build(root); + + const auto dialect = guessDialect(wkt); + if (dialect == WKTGuessedDialect::WKT1_GDAL || + dialect == WKTGuessedDialect::WKT1_ESRI) { + auto errorMsg = pj_wkt1_parse(wkt); + if (!errorMsg.empty()) { + d->emitRecoverableAssertion(errorMsg); + } + } + + return obj; } // --------------------------------------------------------------------------- |
