Skip to content

Commit dc289ad

Browse files
authored
Merge pull request #4331 from rouault/projjson_projected_crs_base_crs_type
PROJJSON export: for a Projected CRS, add an explicit type=GeographicCRS/GeodeticCRS members to the base_crs member
2 parents 6a1e2dc + 17fe008 commit dc289ad

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

docs/source/specifications/projjson.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ The EPSG:32631 / "WGS 84 / UTM zone 31N" projected CRS can be expressed as
504504
"type": "ProjectedCRS",
505505
"name": "WGS 84 / UTM zone 31N",
506506
"base_crs": {
507+
"type": "GeographicCRS",
507508
"name": "WGS 84",
508509
"datum": {
509510
"type": "GeodeticReferenceFrame",
@@ -623,6 +624,12 @@ The EPSG:32631 / "WGS 84 / UTM zone 31N" projected CRS can be expressed as
623624
}
624625
}
625626
627+
628+
.. note::
629+
630+
The ``type`` member of the ``base_crs`` member was omitted in PROJ export of PROJJSON
631+
prior to PROJ 9.6.
632+
626633
CompoundCRS
627634
+++++++++++
628635

src/iso19111/crs.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4533,7 +4533,6 @@ void ProjectedCRS::_exportToJSON(
45334533

45344534
writer->AddObjKey("base_crs");
45354535
formatter->setAllowIDInImmediateChild();
4536-
formatter->setOmitTypeInImmediateChild();
45374536
baseCRS()->_exportToJSON(formatter);
45384537

45394538
writer->AddObjKey("conversion");

test/unit/test_io.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15133,8 +15133,14 @@ TEST(json_import, projected_crs) {
1513315133
auto obj = createFromUserInput(json, nullptr);
1513415134
auto pcrs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
1513515135
ASSERT_TRUE(pcrs != nullptr);
15136-
EXPECT_EQ(pcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))),
15137-
json);
15136+
std::string got_json =
15137+
pcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo")));
15138+
const char *typeGeogCRS = " \"type\": \"GeographicCRS\",\n";
15139+
const auto posTypeGeogCRS = got_json.find(typeGeogCRS);
15140+
EXPECT_TRUE(posTypeGeogCRS != std::string::npos) << got_json;
15141+
got_json = got_json.substr(0, posTypeGeogCRS) +
15142+
got_json.substr(posTypeGeogCRS + strlen(typeGeogCRS));
15143+
EXPECT_STREQ(got_json.c_str(), json);
1513815144
}
1513915145

1514015146
// ---------------------------------------------------------------------------
@@ -15363,8 +15369,14 @@ TEST(json_import, projected_crs_with_geocentric_base) {
1536315369
auto pcrs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
1536415370
ASSERT_TRUE(pcrs != nullptr);
1536515371
EXPECT_TRUE(pcrs->baseCRS()->isGeocentric());
15366-
EXPECT_EQ(pcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo"))),
15367-
json);
15372+
std::string got_json =
15373+
pcrs->exportToJSON(&(JSONFormatter::create()->setSchema("foo")));
15374+
const char *typeGeodCRS = " \"type\": \"GeodeticCRS\",\n";
15375+
const auto posTypeGeodCRS = got_json.find(typeGeodCRS);
15376+
EXPECT_TRUE(posTypeGeodCRS != std::string::npos) << got_json;
15377+
got_json = got_json.substr(0, posTypeGeodCRS) +
15378+
got_json.substr(posTypeGeodCRS + strlen(typeGeodCRS));
15379+
EXPECT_STREQ(got_json.c_str(), json);
1536815380
}
1536915381

1537015382
// ---------------------------------------------------------------------------
@@ -16153,6 +16165,7 @@ TEST(json_import, concatenated_operation) {
1615316165
" \"type\": \"ProjectedCRS\",\n"
1615416166
" \"name\": \"GDA94 / Vicgrid\",\n"
1615516167
" \"base_crs\": {\n"
16168+
" \"type\": \"GeographicCRS\",\n"
1615616169
" \"name\": \"GDA94\",\n"
1615716170
" \"datum\": {\n"
1615816171
" \"type\": \"GeodeticReferenceFrame\",\n"
@@ -17371,6 +17384,7 @@ TEST(json_import, derived_projected_crs) {
1737117384
" \"type\": \"ProjectedCRS\",\n"
1737217385
" \"name\": \"WGS 84 / UTM zone 31N\",\n"
1737317386
" \"base_crs\": {\n"
17387+
" \"type\": \"GeographicCRS\",\n"
1737417388
" \"name\": \"WGS 84\",\n"
1737517389
" \"datum\": {\n"
1737617390
" \"type\": \"GeodeticReferenceFrame\",\n"

0 commit comments

Comments
 (0)