aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-01-11 00:25:51 +0100
committerEven Rouault <even.rouault@spatialys.com>2020-01-11 00:36:10 +0100
commitd2674e044505d0fcee920f5c0315d8db6b842caa (patch)
tree169d397482121ee5582a9aa48502cc72ef8f1ac9 /src
parent39ffdcadbd16fdfbf961973be94ae8479441e411 (diff)
downloadPROJ-d2674e044505d0fcee920f5c0315d8db6b842caa.tar.gz
PROJ-d2674e044505d0fcee920f5c0315d8db6b842caa.zip
WKT1_GDAL export: limit datum name massaging to names matching EPSG (fixes #1835)
Diffstat (limited to 'src')
-rw-r--r--src/iso19111/datum.cpp36
1 files changed, 31 insertions, 5 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";
}