aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-01-04 19:25:04 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-01-04 19:25:04 +0100
commitb62fdee0f34d960527af8fb0a8bf6344fcf78d4b (patch)
tree0341b02ba45f0a3d1761adde97d3c58a220e73ac /src
parentd89a6ab2f3f26d1451971369b0ccfc4eb322729d (diff)
downloadPROJ-b62fdee0f34d960527af8fb0a8bf6344fcf78d4b.tar.gz
PROJ-b62fdee0f34d960527af8fb0a8bf6344fcf78d4b.zip
WKT export: no longer export Geographic 3D CRS in WKT1, unless strict mode is disabled
Diffstat (limited to 'src')
-rw-r--r--src/apps/projinfo.cpp16
-rw-r--r--src/iso19111/c_api.cpp2
-rw-r--r--src/iso19111/crs.cpp23
-rw-r--r--src/iso19111/io.cpp3
4 files changed, 32 insertions, 12 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;