aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsnowman2 <alansnow21@gmail.com>2020-01-01 20:29:16 -0600
committerEven Rouault <even.rouault@spatialys.com>2020-01-02 13:30:48 +0100
commitb391fbc78b57361fb5c9da00b900056237cd091a (patch)
tree741c945fc75147af8d6c64bd0e9fb4025ea6b8ff
parent6baadad43be12376aa26fc44b3711f39f1cabd56 (diff)
downloadPROJ-b391fbc78b57361fb5c9da00b900056237cd091a.tar.gz
PROJ-b391fbc78b57361fb5c9da00b900056237cd091a.zip
fix exporting CoordinateSystem to PROJ JSON with ID
-rw-r--r--src/iso19111/coordinatesystem.cpp12
-rw-r--r--test/unit/test_io.cpp37
2 files changed, 44 insertions, 5 deletions
diff --git a/src/iso19111/coordinatesystem.cpp b/src/iso19111/coordinatesystem.cpp
index 163f0f43..fc4b7492 100644
--- a/src/iso19111/coordinatesystem.cpp
+++ b/src/iso19111/coordinatesystem.cpp
@@ -581,11 +581,13 @@ void CoordinateSystem::_exportToJSON(
writer.Add(getWKT2Type(true));
writer.AddObjKey("axis");
- auto axisContext(writer.MakeArrayContext(false));
- const auto &l_axisList = axisList();
- for (auto &axis : l_axisList) {
- formatter->setOmitTypeInImmediateChild();
- axis->_exportToJSON(formatter);
+ {
+ auto axisContext(writer.MakeArrayContext(false));
+ const auto &l_axisList = axisList();
+ for (auto &axis : l_axisList) {
+ formatter->setOmitTypeInImmediateChild();
+ axis->_exportToJSON(formatter);
+ }
}
if (formatter->outputId()) {
diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp
index 4242a15c..d165157d 100644
--- a/test/unit/test_io.cpp
+++ b/test/unit/test_io.cpp
@@ -11915,3 +11915,40 @@ TEST(json_import, multiple_ids) {
EXPECT_EQ(ellps->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))),
json);
}
+
+// ---------------------------------------------------------------------------
+
+TEST(json_export, coordinate_system_id) {
+ auto json = "{\n"
+ " \"$schema\": \"foo\",\n"
+ " \"type\": \"CoordinateSystem\",\n"
+ " \"subtype\": \"ellipsoidal\",\n"
+ " \"axis\": [\n"
+ " {\n"
+ " \"name\": \"Geodetic latitude\",\n"
+ " \"abbreviation\": \"Lat\",\n"
+ " \"direction\": \"north\",\n"
+ " \"unit\": \"degree\"\n"
+ " },\n"
+ " {\n"
+ " \"name\": \"Geodetic longitude\",\n"
+ " \"abbreviation\": \"Lon\",\n"
+ " \"direction\": \"east\",\n"
+ " \"unit\": \"degree\"\n"
+ " }\n"
+ " ],\n"
+ " \"id\": {\n"
+ " \"authority\": \"EPSG\",\n"
+ " \"code\": 6422\n"
+ " }\n"
+ "}";
+
+ auto dbContext = DatabaseContext::create();
+ auto obj = createFromUserInput("EPSG:4326", dbContext);
+ auto crs = nn_dynamic_pointer_cast<GeographicCRS>(obj);
+ ASSERT_TRUE(crs != nullptr);
+ auto cs = crs->coordinateSystem();
+ ASSERT_TRUE(cs != nullptr);
+ EXPECT_EQ(cs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))),
+ json);
+}