diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-06-06 10:49:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-06 10:49:35 +0200 |
| commit | e148569769c202226aa73297af3d253f9e839aa4 (patch) | |
| tree | 139f1a832d30ac484fd1515679bb25daf6640eeb | |
| parent | 0383f7829792f896d233acc1676377d2fffc3cdc (diff) | |
| parent | cd33f64657ca575906a70371ff70a881f0a8e6c3 (diff) | |
| download | PROJ-e148569769c202226aa73297af3d253f9e839aa4.tar.gz PROJ-e148569769c202226aa73297af3d253f9e839aa4.zip | |
Merge pull request #1506 from rouault/do_not_confuse_ID74_with_WKT
createFromUserInput()/guessDialect(): do not confuse 'ID74' CRS with WKT2 ID[] node
| -rw-r--r-- | src/iso19111/io.cpp | 34 | ||||
| -rw-r--r-- | test/unit/test_io.cpp | 3 |
2 files changed, 28 insertions, 9 deletions
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 7329758a..17673c5f 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -4377,12 +4377,20 @@ static BaseObjectNNPtr createFromUserInput(const std::string &text, if (!ci_starts_with(text, "step proj=") && !ci_starts_with(text, "step +proj=")) { - for (const auto &wktConstants : WKTConstants::constants()) { - if (ci_starts_with(text, wktConstants)) { - return WKTParser() - .attachDatabaseContext(dbContext) - .setStrict(false) - .createFromWKT(text); + for (const auto &wktConstant : WKTConstants::constants()) { + if (ci_starts_with(text, wktConstant)) { + for (auto wkt = text.c_str() + wktConstant.size(); *wkt != '\0'; + ++wkt) { + if (isspace(static_cast<unsigned char>(*wkt))) + continue; + if (*wkt == '[') { + return WKTParser() + .attachDatabaseContext(dbContext) + .setStrict(false) + .createFromWKT(text); + } + break; + } } } } @@ -4778,9 +4786,17 @@ WKTParser::guessDialect(const std::string &wkt) noexcept { } } - for (const auto &wktConstants : WKTConstants::constants()) { - if (ci_starts_with(wkt, wktConstants)) { - return WKTGuessedDialect::WKT2_2015; + for (const auto &wktConstant : WKTConstants::constants()) { + if (ci_starts_with(wkt, wktConstant)) { + for (auto wktPtr = wkt.c_str() + wktConstant.size(); + *wktPtr != '\0'; ++wktPtr) { + if (isspace(static_cast<unsigned char>(*wktPtr))) + continue; + if (*wktPtr == '[') { + return WKTGuessedDialect::WKT2_2015; + } + break; + } } } diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 294e765d..820e052a 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -8906,6 +8906,7 @@ TEST(io, createFromUserInput) { EXPECT_THROW(createFromUserInput("UTM zone 31", dbContext), ParsingException); EXPECT_NO_THROW(createFromUserInput("WGS84 UTM zone 31N", dbContext)); + EXPECT_NO_THROW(createFromUserInput("ID74", dbContext)); } // --------------------------------------------------------------------------- @@ -8951,6 +8952,8 @@ TEST(io, guessDialect) { EXPECT_EQ(WKTParser().guessDialect("foo"), WKTParser::WKTGuessedDialect::NOT_WKT); + EXPECT_EQ(WKTParser().guessDialect("ID74"), + WKTParser::WKTGuessedDialect::NOT_WKT); } // --------------------------------------------------------------------------- |
