aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/proj/io.hpp3
-rw-r--r--src/iso19111/crs.cpp11
-rw-r--r--test/unit/test_crs.cpp3
-rw-r--r--test/unit/test_io.cpp29
4 files changed, 41 insertions, 5 deletions
diff --git a/include/proj/io.hpp b/include/proj/io.hpp
index 8cf8e3c4..90163001 100644
--- a/include/proj/io.hpp
+++ b/include/proj/io.hpp
@@ -195,8 +195,7 @@ class PROJ_GCC_DLL WKTFormatter {
WKT2_2018_SIMPLIFIED,
/** WKT1 as traditionally output by GDAL, deriving from OGC 01-009.
- A notable departuPROJ_GCC_DLLre from WKT1_GDAL with respect to OGC
- 01-009 is
+ A notable departure from WKT1_GDAL with respect to OGC 01-009 is
that in WKT1_GDAL, the unit of the PRIMEM value is always degrees.
*/
WKT1_GDAL,
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp
index 74f6f999..9779d817 100644
--- a/src/iso19111/crs.cpp
+++ b/src/iso19111/crs.cpp
@@ -2428,9 +2428,13 @@ void DerivedCRS::baseExportToWKT(io::WKTFormatter *formatter,
formatter->addQuotedString(nameStr());
const auto &l_baseCRS = d->baseCRS_;
- formatter->startNode(baseKeyword, !l_baseCRS->identifiers().empty());
+ formatter->startNode(baseKeyword, formatter->use2018Keywords() &&
+ !l_baseCRS->identifiers().empty());
formatter->addQuotedString(l_baseCRS->nameStr());
l_baseCRS->exportDatumOrDatumEnsembleToWkt(formatter);
+ if (formatter->use2018Keywords() && formatter->outputId()) {
+ l_baseCRS->formatID(formatter);
+ }
formatter->endNode();
formatter->setUseDerivingConversion(true);
@@ -2658,7 +2662,7 @@ void ProjectedCRS::_exportToWKT(io::WKTFormatter *formatter) const {
dynamic_cast<const GeographicCRS *>(l_baseCRS.get()))
? io::WKTConstants::BASEGEOGCRS
: io::WKTConstants::BASEGEODCRS,
- !l_baseCRS->identifiers().empty());
+ formatter->use2018Keywords() && !l_baseCRS->identifiers().empty());
formatter->addQuotedString(l_baseCRS->nameStr());
l_baseCRS->exportDatumOrDatumEnsembleToWkt(formatter);
// insert ellipsoidal cs unit when the units of the map
@@ -2669,6 +2673,9 @@ void ProjectedCRS::_exportToWKT(io::WKTFormatter *formatter) const {
geodeticCRSAxisList[0]->unit()._exportToWKT(formatter);
}
l_baseCRS->primeMeridian()->_exportToWKT(formatter);
+ if (formatter->use2018Keywords() && formatter->outputId()) {
+ l_baseCRS->formatID(formatter);
+ }
formatter->endNode();
} else {
const auto oldAxisOutputRule = formatter->outputAxis();
diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp
index 02586877..bfd6ee66 100644
--- a/test/unit/test_crs.cpp
+++ b/test/unit/test_crs.cpp
@@ -4562,7 +4562,8 @@ TEST(crs, DerivedVerticalCRS_WKT2) {
auto expected = "VERTCRS[\"Derived vertCRS\",\n"
" BASEVERTCRS[\"ODN height\",\n"
- " VDATUM[\"Ordnance Datum Newlyn\"]],\n"
+ " VDATUM[\"Ordnance Datum Newlyn\",\n"
+ " ID[\"EPSG\",5101]]],\n"
" DERIVINGCONVERSION[\"unnamed\",\n"
" METHOD[\"PROJ unimplemented\"]],\n"
" CS[vertical,1],\n"
diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp
index 1d097d9b..2181b321 100644
--- a/test/unit/test_io.cpp
+++ b/test/unit/test_io.cpp
@@ -1667,6 +1667,35 @@ TEST(wkt_parse, wkt2_2018_projected_with_id_in_basegeodcrs) {
// ---------------------------------------------------------------------------
+TEST(wkt_parse, wkt2_2018_projected_no_id_but_id_in_basegeodcrs) {
+ auto wkt = "PROJCRS[\"WGS 84 / UTM zone 31N\",\n"
+ " BASEGEOGCRS[\"WGS 84\",\n"
+ " DATUM[\"World Geodetic System 1984\",\n"
+ " ELLIPSOID[\"WGS 84\",6378137,298.257223563]],\n"
+ " ID[\"EPSG\",4326]],\n"
+ " CONVERSION[\"UTM zone 31N\",\n"
+ " METHOD[\"Transverse Mercator\"],\n"
+ " PARAMETER[\"Latitude of natural origin\",0],\n"
+ " PARAMETER[\"Longitude of natural origin\",3],\n"
+ " PARAMETER[\"Scale factor at natural origin\",0.9996],\n"
+ " PARAMETER[\"False easting\",500000],\n"
+ " PARAMETER[\"False northing\",0]],\n"
+ " CS[Cartesian,2],\n"
+ " AXIS[\"(E)\",east],\n"
+ " AXIS[\"(N)\",north],\n"
+ " UNIT[\"metre\",1]]";
+ auto obj = WKTParser().createFromWKT(wkt);
+ auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
+ ASSERT_TRUE(crs != nullptr);
+
+ auto got_wkt = crs->exportToWKT(
+ WKTFormatter::create(WKTFormatter::Convention::WKT2_2018).get());
+ EXPECT_TRUE(got_wkt.find("ID[\"EPSG\",4326]]") != std::string::npos)
+ << got_wkt;
+}
+
+// ---------------------------------------------------------------------------
+
TEST(wkt_parse, wkt2_2018_simplified_projected) {
auto wkt = "PROJCRS[\"WGS 84 / UTM zone 31N\",\n"
" BASEGEOGCRS[\"WGS 84\",\n"