aboutsummaryrefslogtreecommitdiff
path: root/src/iso19111
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-01-17 10:40:12 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-01-17 10:40:12 +0100
commit3121d9bc309b439adcc2ab9743a3d2b3a8f48296 (patch)
tree9c6bb780646a9f074373e0acb18414b91ffc61a9 /src/iso19111
parent6d2af0904652baba69ec81261c914e9b68221dac (diff)
downloadPROJ-3121d9bc309b439adcc2ab9743a3d2b3a8f48296.tar.gz
PROJ-3121d9bc309b439adcc2ab9743a3d2b3a8f48296.zip
import/export PROJ strings from ISO19111 code: require/output +type=crs for CRS objects (refs #1214)
Diffstat (limited to 'src/iso19111')
-rw-r--r--src/iso19111/crs.cpp9
-rw-r--r--src/iso19111/factory.cpp6
-rw-r--r--src/iso19111/io.cpp23
3 files changed, 31 insertions, 7 deletions
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp
index 81c70b7a..a003cd9c 100644
--- a/src/iso19111/crs.cpp
+++ b/src/iso19111/crs.cpp
@@ -1176,7 +1176,8 @@ void GeodeticCRS::_exportToPROJString(
{
const auto &extensionProj4 = CRS::getPrivate()->extensionProj4_;
if (!extensionProj4.empty()) {
- formatter->ingestPROJString(extensionProj4);
+ formatter->ingestPROJString(
+ replaceAll(extensionProj4, " +type=crs", ""));
formatter->addNoDefs(false);
return;
}
@@ -1907,7 +1908,8 @@ void GeographicCRS::_exportToPROJString(
{
const auto &extensionProj4 = CRS::getPrivate()->extensionProj4_;
if (!extensionProj4.empty()) {
- formatter->ingestPROJString(extensionProj4);
+ formatter->ingestPROJString(
+ replaceAll(extensionProj4, " +type=crs", ""));
formatter->addNoDefs(false);
return;
}
@@ -2719,7 +2721,8 @@ void ProjectedCRS::_exportToPROJString(
{
const auto &extensionProj4 = CRS::getPrivate()->extensionProj4_;
if (!extensionProj4.empty()) {
- formatter->ingestPROJString(extensionProj4);
+ formatter->ingestPROJString(
+ replaceAll(extensionProj4, " +type=crs", ""));
formatter->addNoDefs(false);
return;
}
diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp
index 3b6563f3..565f43e3 100644
--- a/src/iso19111/factory.cpp
+++ b/src/iso19111/factory.cpp
@@ -2086,7 +2086,8 @@ AuthorityFactory::createGeodeticCRS(const std::string &code,
if (!text_definition.empty()) {
DatabaseContext::Private::RecursionDetector detector(d->context());
- auto obj = createFromUserInput(text_definition, d->context());
+ auto obj = createFromUserInput(
+ pj_add_type_crs_if_needed(text_definition), d->context());
auto geodCRS = util::nn_dynamic_pointer_cast<crs::GeodeticCRS>(obj);
if (geodCRS) {
return cloneWithProps(NN_NO_CHECK(geodCRS), props);
@@ -2333,7 +2334,8 @@ AuthorityFactory::createProjectedCRS(const std::string &code) const {
if (!text_definition.empty()) {
DatabaseContext::Private::RecursionDetector detector(d->context());
- auto obj = createFromUserInput(text_definition, d->context());
+ auto obj = createFromUserInput(
+ pj_add_type_crs_if_needed(text_definition), d->context());
auto projCRS = dynamic_cast<const crs::ProjectedCRS *>(obj.get());
if (projCRS) {
const auto &conv = projCRS->derivingConversionRef();
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp
index 5be02ffe..d403495b 100644
--- a/src/iso19111/io.cpp
+++ b/src/iso19111/io.cpp
@@ -3344,6 +3344,9 @@ ConversionNNPtr WKTParser::Private::buildProjectionStandard(
ci_equal(stripQuotes(extensionChildren[0]), "PROJ4")) {
std::string projString = stripQuotes(extensionChildren[1]);
if (starts_with(projString, "+proj=")) {
+ if (projString.find(" +type=crs") == std::string::npos) {
+ projString += " +type=crs";
+ }
try {
auto projObj =
PROJStringParser().createFromPROJString(projString);
@@ -4619,6 +4622,9 @@ std::string IPROJStringExportable::exportToPROJString(
}
}
if (bIsCRS) {
+ if (!formatter->hasParam("type")) {
+ formatter->addParam("type", "crs");
+ }
formatter->setCRSExport(false);
}
return formatter->toString();
@@ -5303,6 +5309,9 @@ PROJStringSyntaxParser(const std::string &projString, std::vector<Step> &steps,
vunits = word.substr(strlen("vunits="));
} else if (starts_with(word, "vto_meter=")) {
vto_meter = word.substr(strlen("vto_meter="));
+ } else if (word == "type=crs" &&
+ (!vunits.empty() || !vto_meter.empty())) {
+ // ok
} else if (starts_with(word, "title=")) {
title = word.substr(strlen("title="));
prevWasTitle = true;
@@ -6902,7 +6911,7 @@ CRSNNPtr PROJStringParser::Private::buildProjectedCRS(
param.key == "towgs84" || param.key == "nadgrids" ||
param.key == "geoidgrids" || param.key == "units" ||
param.key == "to_meter" || param.key == "vunits" ||
- param.key == "vto_meter") {
+ param.key == "vto_meter" || param.key == "type") {
continue;
}
if (param.value.empty()) {
@@ -7252,6 +7261,10 @@ static const metadata::ExtentPtr &getExtent(const crs::CRS *crs) {
// ---------------------------------------------------------------------------
/** \brief Instantiate a sub-class of BaseObject from a PROJ string.
+ *
+ * The projString must contain +type=crs for the object to be detected as a
+ * CRS instead of a CoordinateOperation.
+ *
* @throw ParsingException
*/
BaseObjectNNPtr
@@ -7300,7 +7313,8 @@ PROJStringParser::createFromPROJString(const std::string &projString) {
// +init=xxxx:yyyy syntax
if (d->steps_.size() == 1 && d->steps_[0].isInit &&
- d->steps_[0].paramValues.size() == 0) {
+ (d->steps_[0].paramValues.size() == 0 ||
+ d->getParamValue(d->steps_[0], "type") == "crs")) {
// Those used to come from a text init file
// We only support them in compatibility mode
@@ -7483,6 +7497,11 @@ PROJStringParser::createFromPROJString(const std::string &projString) {
}
}
+ if (d->steps_.size() == 1 && iHelmert < 0 && iMolodensky < 0 &&
+ d->getParamValue(d->steps_[0], "type") != "crs") {
+ unexpectedStructure = true;
+ }
+
if (!unexpectedStructure) {
if (iFirstGeogStep == 0 && iSecondGeogStep < 0 && iProjStep < 0 &&
iHelmert < 0 && iFirstCart < 0 && iMolodensky < 0 &&