diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-01-05 19:56:03 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-01-05 19:56:03 +0100 |
| commit | 0fbe7cf33c308c4b7c81e65e18b90e9d773ba333 (patch) | |
| tree | e0bdd52d3ebb96edd97df9a8e385fc9af6dd15c2 | |
| parent | 3ea468222fdabdae3aa5b47439d6b3bfb0a93c8e (diff) | |
| parent | b62fdee0f34d960527af8fb0a8bf6344fcf78d4b (diff) | |
| download | PROJ-0fbe7cf33c308c4b7c81e65e18b90e9d773ba333.tar.gz PROJ-0fbe7cf33c308c4b7c81e65e18b90e9d773ba333.zip | |
Merge remote-tracking branch 'rouault/gdalbarn'
| -rw-r--r-- | src/apps/projinfo.cpp | 16 | ||||
| -rw-r--r-- | src/iso19111/c_api.cpp | 2 | ||||
| -rw-r--r-- | src/iso19111/crs.cpp | 23 | ||||
| -rw-r--r-- | src/iso19111/io.cpp | 3 | ||||
| -rw-r--r-- | test/unit/test_c_api.cpp | 19 | ||||
| -rw-r--r-- | test/unit/test_crs.cpp | 22 |
6 files changed, 59 insertions, 26 deletions
diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 4fcd3e5e..b418bc57 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -70,6 +70,7 @@ struct OutputOptions { bool WKT1_ESRI = false; bool c_ify = false; bool singleLine = false; + bool strict = true; }; } // anonymous namespace @@ -321,6 +322,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (outputOpt.singleLine) { formatter->setMultiLine(false); } + formatter->setStrict(outputOpt.strict); auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); @@ -346,6 +348,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (outputOpt.singleLine) { formatter->setMultiLine(false); } + formatter->setStrict(outputOpt.strict); auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); @@ -371,6 +374,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (outputOpt.singleLine) { formatter->setMultiLine(false); } + formatter->setStrict(outputOpt.strict); auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); @@ -396,6 +400,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (outputOpt.singleLine) { formatter->setMultiLine(false); } + formatter->setStrict(outputOpt.strict); auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); @@ -433,6 +438,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (outputOpt.singleLine) { formatter->setMultiLine(false); } + formatter->setStrict(outputOpt.strict); auto wkt = objToExport->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); @@ -455,10 +461,10 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, std::cout << "WKT1_ESRI:" << std::endl; } - auto wkt = wktExportable->exportToWKT( - WKTFormatter::create(WKTFormatter::Convention::WKT1_ESRI, - dbContext) - .get()); + auto formatter = WKTFormatter::create( + WKTFormatter::Convention::WKT1_ESRI, dbContext); + formatter->setStrict(outputOpt.strict); + auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); } @@ -862,6 +868,8 @@ int main(int argc, char **argv) { identify = true; } else if (arg == "--show-superseded") { showSuperseded = true; + } else if (arg == "--lax") { + outputOpt.strict = false; } else if (arg == "-?" || arg == "--help") { usage(); } else if (arg[0] == '-') { diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index c3c2fa39..70488de4 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -1245,6 +1245,8 @@ const char *proj_as_wkt(PJ_CONTEXT *ctx, const PJ *obj, PJ_WKT_TYPE type, ? WKTFormatter::OutputAxisRule::YES : WKTFormatter::OutputAxisRule::NO); } + } else if ((value = getOptionValue(*iter, "STRICT="))) { + formatter->setStrict(ci_equal(value, "YES")); } else { std::string msg("Unknown option :"); msg += *iter; diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index eec36fee..190291de 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -1046,17 +1046,21 @@ GeodeticCRS::create(const util::PropertyMap &properties, //! @cond Doxygen_Suppress void GeodeticCRS::_exportToWKT(io::WKTFormatter *formatter) const { const bool isWKT2 = formatter->version() == io::WKTFormatter::Version::WKT2; - formatter->startNode(isWKT2 ? ((formatter->use2018Keywords() && - dynamic_cast<const GeographicCRS *>(this)) - ? io::WKTConstants::GEOGCRS - : io::WKTConstants::GEODCRS) - : isGeocentric() ? io::WKTConstants::GEOCCS - : io::WKTConstants::GEOGCS, + const bool isGeographic = + dynamic_cast<const GeographicCRS *>(this) != nullptr; + formatter->startNode(isWKT2 + ? ((formatter->use2018Keywords() && isGeographic) + ? io::WKTConstants::GEOGCRS + : io::WKTConstants::GEODCRS) + : isGeocentric() ? io::WKTConstants::GEOCCS + : io::WKTConstants::GEOGCS, !identifiers().empty()); auto l_name = nameStr(); const auto &cs = coordinateSystem(); const auto &axisList = cs->axisList(); + const auto oldAxisOutputRule = formatter->outputAxis(); + if (formatter->useESRIDialect()) { if (axisList.size() != 2) { io::FormattingException::Throw( @@ -1083,7 +1087,13 @@ void GeodeticCRS::_exportToWKT(io::WKTFormatter *formatter) const { } } } + } else if (!isWKT2 && formatter->isStrict() && isGeographic && + axisList.size() != 2 && + oldAxisOutputRule != io::WKTFormatter::OutputAxisRule::NO) { + io::FormattingException::Throw( + "WKT1 does not support Geographic 3D CRS."); } + if (!isWKT2 && !formatter->useESRIDialect() && isDeprecated()) { l_name += " (deprecated)"; } @@ -1098,7 +1108,6 @@ void GeodeticCRS::_exportToWKT(io::WKTFormatter *formatter) const { unit._exportToWKT(formatter); } - const auto oldAxisOutputRule = formatter->outputAxis(); if (oldAxisOutputRule == io::WKTFormatter::OutputAxisRule::WKT1_GDAL_EPSG_STYLE && isGeocentric()) { diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 6a2c3e1a..cfccd70f 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -239,7 +239,8 @@ WKTFormatter::setOutputAxis(OutputAxisRule outputAxisIn) noexcept { /** \brief Set whether the formatter should operate on strict more or not. * - * The default is strit mode, in which case a FormattingException can be thrown. + * The default is strict mode, in which case a FormattingException can be + * thrown. */ WKTFormatter &WKTFormatter::setStrict(bool strictIn) noexcept { d->params_.strict_ = strictIn; diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index 096d970b..778c6bdf 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -420,6 +420,25 @@ TEST_F(CApi, proj_as_wkt) { EXPECT_TRUE(std::string(wkt).find("AXIS") != std::string::npos) << wkt; } + auto crs4979 = proj_create_from_wkt( + m_ctxt, + GeographicCRS::EPSG_4979->exportToWKT(WKTFormatter::create().get()) + .c_str(), + nullptr, nullptr, nullptr); + ObjectKeeper keeper_crs4979(crs4979); + ASSERT_NE(crs4979, nullptr); + + // STRICT=NO + { + EXPECT_EQ(proj_as_wkt(m_ctxt, crs4979, PJ_WKT1_GDAL, nullptr), nullptr); + + const char *const options[] = {"STRICT=NO", nullptr}; + auto wkt = proj_as_wkt(m_ctxt, crs4979, PJ_WKT1_GDAL, options); + ASSERT_NE(wkt, nullptr); + EXPECT_TRUE(std::string(wkt).find("GEOGCS[\"WGS 84\"") == 0) + << wkt; + } + // unsupported option { const char *const options[] = {"unsupported=yes", nullptr}; diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index 6eb0602e..fe0ac7e8 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -442,14 +442,16 @@ TEST(crs, EPSG_4979_as_WKT2_2018_SIMPLIFIED) { // --------------------------------------------------------------------------- -TEST(crs, EPSG_4979_as_WKT1_GDAL_with_axis) { +TEST(crs, EPSG_4979_as_WKT1_GDAL_with_axis_not_strict_mode) { auto crs = GeographicCRS::EPSG_4979; auto wkt = crs->exportToWKT( &(WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL) - ->setOutputAxis(WKTFormatter::OutputAxisRule::YES))); + ->setStrict(false) + .setOutputAxis(WKTFormatter::OutputAxisRule::YES))); // WKT1 only supports 2 axis for GEOGCS. So this is an extension of // WKT1 as it // and GDAL doesn't really export such as beast, although it can import it + // so allow it only in non-strict more EXPECT_EQ(wkt, "GEOGCS[\"WGS 84\",\n" " DATUM[\"WGS_1984\",\n" " SPHEROID[\"WGS 84\",6378137,298.257223563,\n" @@ -469,18 +471,10 @@ TEST(crs, EPSG_4979_as_WKT1_GDAL_with_axis) { TEST(crs, EPSG_4979_as_WKT1_GDAL) { auto crs = GeographicCRS::EPSG_4979; - auto wkt = crs->exportToWKT( - WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get()); - EXPECT_EQ(wkt, "GEOGCS[\"WGS 84\",\n" - " DATUM[\"WGS_1984\",\n" - " SPHEROID[\"WGS 84\",6378137,298.257223563,\n" - " AUTHORITY[\"EPSG\",\"7030\"]],\n" - " AUTHORITY[\"EPSG\",\"6326\"]],\n" - " PRIMEM[\"Greenwich\",0,\n" - " AUTHORITY[\"EPSG\",\"8901\"]],\n" - " UNIT[\"degree\",0.0174532925199433,\n" - " AUTHORITY[\"EPSG\",\"9122\"]],\n" - " AUTHORITY[\"EPSG\",\"4979\"]]"); + EXPECT_THROW( + crs->exportToWKT( + WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get()), + FormattingException); } // --------------------------------------------------------------------------- |
