diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-01-11 12:01:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-11 12:01:59 +0100 |
| commit | 1b7df035f9084096d7ffd49c26618dc0d8ac1c94 (patch) | |
| tree | 16e9d42a37c876743516281b53f9eaf075658e01 | |
| parent | 921541789ce1203875b36e2ac4726c0447b17a18 (diff) | |
| parent | d2674e044505d0fcee920f5c0315d8db6b842caa (diff) | |
| download | PROJ-1b7df035f9084096d7ffd49c26618dc0d8ac1c94.tar.gz PROJ-1b7df035f9084096d7ffd49c26618dc0d8ac1c94.zip | |
Merge pull request #1838 from rouault/limit_datum_name_massaging_wkt1
WKT1_GDAL export: limit datum name massaging to names matching EPSG (fixes #1835)
| -rw-r--r-- | src/iso19111/datum.cpp | 36 | ||||
| -rw-r--r-- | test/unit/test_crs.cpp | 14 | ||||
| -rw-r--r-- | test/unit/test_operation.cpp | 4 |
3 files changed, 44 insertions, 10 deletions
diff --git a/src/iso19111/datum.cpp b/src/iso19111/datum.cpp index 255f9822..d9d9c261 100644 --- a/src/iso19111/datum.cpp +++ b/src/iso19111/datum.cpp @@ -1201,7 +1201,8 @@ void GeodeticReferenceFrame::_exportToWKT( io::WKTFormatter *formatter) const // throw(FormattingException) { const bool isWKT2 = formatter->version() == io::WKTFormatter::Version::WKT2; - formatter->startNode(io::WKTConstants::DATUM, !identifiers().empty()); + const auto &ids = identifiers(); + formatter->startNode(io::WKTConstants::DATUM, !ids.empty()); auto l_name = nameStr(); if (l_name.empty()) { l_name = "unnamed"; @@ -1236,10 +1237,35 @@ void GeodeticReferenceFrame::_exportToWKT( } } } - // Replace spaces by underscore, except if it is a special MapInfo - // datum name - } else if (!starts_with(l_name, "MIF ")) { - l_name = io::WKTFormatter::morphNameToESRI(l_name); + } else { + // Replace spaces by underscore for datum names coming from EPSG + // so as to emulate GDAL < 3 importFromEPSG() + if (ids.size() == 1 && *(ids.front()->codeSpace()) == "EPSG") { + l_name = io::WKTFormatter::morphNameToESRI(l_name); + } else if (ids.empty()) { + const auto &dbContext = formatter->databaseContext(); + if (dbContext) { + auto factory = io::AuthorityFactory::create( + NN_NO_CHECK(dbContext), std::string()); + // We use anonymous autority and approximate matching, so + // as to trigger the caching done in createObjectsFromName() + // in that case. + auto matches = factory->createObjectsFromName( + l_name, {io::AuthorityFactory::ObjectType:: + GEODETIC_REFERENCE_FRAME}, + true, 2); + if (matches.size() == 1) { + const auto &match = matches.front(); + const auto &matchId = match->identifiers(); + if (matchId.size() == 1 && + *(matchId.front()->codeSpace()) == "EPSG" && + metadata::Identifier::isEquivalentName( + l_name.c_str(), match->nameStr().c_str())) { + l_name = io::WKTFormatter::morphNameToESRI(l_name); + } + } + } + } if (l_name == "World_Geodetic_System_1984") { l_name = "WGS_1984"; } diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index 82eb4562..e6189a97 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -756,7 +756,9 @@ TEST(crs, EPSG_27561_projected_with_geodetic_in_grad_as_PROJ_string_and_WKT1) { nn_crs->DerivedCRS::isEquivalentTo(createUnrelatedObject().get())); auto wkt1 = crs->exportToWKT( - WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get()); + WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL, + DatabaseContext::create()) + .get()); EXPECT_EQ( wkt1, "PROJCS[\"NTF (Paris) / Lambert Nord France\",\n" @@ -857,7 +859,9 @@ TEST(crs, EPSG_2222_projected_unit_foot_as_PROJ_string_and_WKT1) { "+x_0=213360 +y_0=0 +datum=NAD83 +units=ft +no_defs +type=crs"); auto wkt1 = crs->exportToWKT( - WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get()); + WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL, + DatabaseContext::create()) + .get()); EXPECT_EQ(wkt1, "PROJCS[\"NAD83 / Arizona East (ft)\",\n" " GEOGCS[\"NAD83\",\n" @@ -904,11 +908,13 @@ TEST(crs, projected_with_parameter_unit_different_than_cs_unit_as_WKT1) { ASSERT_TRUE(crs != nullptr); auto wkt1 = crs->exportToWKT( - WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get()); + WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL, + DatabaseContext::create()) + .get()); EXPECT_EQ(wkt1, "PROJCS[\"unknown\",\n" " GEOGCS[\"unknown\",\n" - " DATUM[\"Unknown_based_on_GRS80_ellipsoid\",\n" + " DATUM[\"Unknown based on GRS80 ellipsoid\",\n" " SPHEROID[\"GRS 1980\",6378137,298.257222101]],\n" " PRIMEM[\"Greenwich\",0],\n" " UNIT[\"degree\",0.0174532925199433,\n" diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp index 316745f5..b2c13b6c 100644 --- a/test/unit/test_operation.cpp +++ b/test/unit/test_operation.cpp @@ -3258,7 +3258,9 @@ TEST(operation, webmerc_import_from_WKT2_EPSG_3785_deprecated) { EXPECT_EQ( crs->exportToWKT( - WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get()), + WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL, + DatabaseContext::create()) + .get()), "PROJCS[\"Popular Visualisation CRS / Mercator\",\n" " GEOGCS[\"Popular Visualisation CRS\",\n" " DATUM[\"Popular_Visualisation_Datum\",\n" |
