aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-01-22 10:58:13 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-01-22 10:58:13 +0100
commitc048292f3b8e408e6a81700a74d9b44d532227ac (patch)
tree4793063b442e2768d7bea3fd1c96f80a55140093 /src
parent5c86b290e2c5686cbf5100eb71e32b0362a989fc (diff)
downloadPROJ-c048292f3b8e408e6a81700a74d9b44d532227ac.tar.gz
PROJ-c048292f3b8e408e6a81700a74d9b44d532227ac.zip
Coordinate operation computation with boundcrs / wktext: drop useless early bindins terms in generated pipeline (fixes #1232)
Diffstat (limited to 'src')
-rw-r--r--src/iso19111/c_api.cpp2
-rw-r--r--src/iso19111/common.cpp3
-rw-r--r--src/iso19111/coordinateoperation.cpp1
-rw-r--r--src/iso19111/crs.cpp8
-rw-r--r--src/iso19111/io.cpp49
5 files changed, 42 insertions, 21 deletions
diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp
index 06a3c02e..de11f181 100644
--- a/src/iso19111/c_api.cpp
+++ b/src/iso19111/c_api.cpp
@@ -337,7 +337,7 @@ PJ *proj_create(PJ_CONTEXT *ctx, const char *text) {
assert(text);
// Only connect to proj.db if needed
- if( strstr(text, "proj=") == nullptr || strstr(text, "init=") != nullptr ) {
+ if (strstr(text, "proj=") == nullptr || strstr(text, "init=") != nullptr) {
getDBcontextNoException(ctx, __FUNCTION__);
}
try {
diff --git a/src/iso19111/common.cpp b/src/iso19111/common.cpp
index ca9d3b3e..57654d84 100644
--- a/src/iso19111/common.cpp
+++ b/src/iso19111/common.cpp
@@ -1122,8 +1122,7 @@ struct DataEpoch::Private {
// ---------------------------------------------------------------------------
-DataEpoch::DataEpoch()
- : d(internal::make_unique<Private>(Measure())) {}
+DataEpoch::DataEpoch() : d(internal::make_unique<Private>(Measure())) {}
// ---------------------------------------------------------------------------
diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp
index 723fddec..6f9b6283 100644
--- a/src/iso19111/coordinateoperation.cpp
+++ b/src/iso19111/coordinateoperation.cpp
@@ -11100,6 +11100,7 @@ CoordinateOperationFactory::Private::createOperations(
}
auto projFormatter = io::PROJStringFormatter::create();
projFormatter->setCRSExport(true);
+ projFormatter->setDropEarlyBindingsTerms(true);
projFormatter->startInversion();
sourceProjExportable->_exportToPROJString(projFormatter.get());
auto geogSrc =
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp
index 74b94a1f..adb441cd 100644
--- a/src/iso19111/crs.cpp
+++ b/src/iso19111/crs.cpp
@@ -1653,8 +1653,7 @@ CRSNNPtr GeographicCRS::_shallowClone() const {
*
* @return a EllipsoidalCS.
*/
-const cs::EllipsoidalCSNNPtr &
-GeographicCRS::coordinateSystem() PROJ_PURE_DEFN {
+const cs::EllipsoidalCSNNPtr &GeographicCRS::coordinateSystem() PROJ_PURE_DEFN {
return d->coordinateSystem_;
}
@@ -3767,6 +3766,11 @@ void BoundCRS::_exportToPROJString(
"baseCRS of BoundCRS cannot be exported as a PROJ string");
}
+ if (formatter->getDropEarlyBindingsTerms()) {
+ crs_exportable->_exportToPROJString(formatter);
+ return;
+ }
+
auto vdatumProj4GridName = getVDatumPROJ4GRIDS();
if (!vdatumProj4GridName.empty()) {
formatter->setVDatumExtension(vdatumProj4GridName);
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp
index 4c417585..0722c22a 100644
--- a/src/iso19111/io.cpp
+++ b/src/iso19111/io.cpp
@@ -4745,6 +4745,7 @@ struct PROJStringFormatter::Private {
bool addNoDefs_ = true;
bool coordOperationOptimizations_ = false;
bool crsExport_ = false;
+ bool dropEarlyBindingsTerms_ = false;
std::string result_{};
@@ -5274,7 +5275,7 @@ void PROJStringFormatter::Private::appendToResult(const char *str) {
static void
PROJStringSyntaxParser(const std::string &projString, std::vector<Step> &steps,
std::vector<Step::KeyValue> &globalParamValues,
- std::string &title) {
+ std::string &title, bool dropEarlyBindingsTerms) {
const char *c_str = projString.c_str();
std::vector<std::string> tokens;
@@ -5352,13 +5353,17 @@ PROJStringSyntaxParser(const std::string &projString, std::vector<Step> &steps,
} else if (word != "step") {
const auto pos = word.find('=');
auto key = word.substr(0, pos);
- auto pair = (pos != std::string::npos)
- ? Step::KeyValue(key, word.substr(pos + 1))
- : Step::KeyValue(key);
- if (steps.empty()) {
- globalParamValues.push_back(pair);
- } else {
- steps.back().paramValues.push_back(pair);
+ if (!(dropEarlyBindingsTerms &&
+ (key == "towgs84" || key == "nadgrids" ||
+ key == "geoidgrids" || key == "wktext"))) {
+ auto pair = (pos != std::string::npos)
+ ? Step::KeyValue(key, word.substr(pos + 1))
+ : Step::KeyValue(key);
+ if (steps.empty()) {
+ globalParamValues.push_back(pair);
+ } else {
+ steps.back().paramValues.push_back(pair);
+ }
}
}
}
@@ -5433,7 +5438,8 @@ void PROJStringFormatter::ingestPROJString(
{
std::vector<Step> steps;
std::string title;
- PROJStringSyntaxParser(str, steps, d->globalParamValues_, title);
+ PROJStringSyntaxParser(str, steps, d->globalParamValues_, title,
+ d->dropEarlyBindingsTerms_);
d->steps_.insert(d->steps_.end(), steps.begin(), steps.end());
}
@@ -5695,6 +5701,18 @@ bool PROJStringFormatter::omitZUnitConversion() const {
// ---------------------------------------------------------------------------
+void PROJStringFormatter::setDropEarlyBindingsTerms(bool drop) {
+ d->dropEarlyBindingsTerms_ = drop;
+}
+
+// ---------------------------------------------------------------------------
+
+bool PROJStringFormatter::getDropEarlyBindingsTerms() const {
+ return d->dropEarlyBindingsTerms_;
+}
+
+// ---------------------------------------------------------------------------
+
const DatabaseContextPtr &PROJStringFormatter::databaseContext() const {
return d->dbContext_;
}
@@ -6673,8 +6691,12 @@ CRSNNPtr
PROJStringParser::Private::buildBoundOrCompoundCRSIfNeeded(int iStep,
CRSNNPtr crs) {
const auto &step = steps_[iStep];
+ const auto &nadgrids = getParamValue(step, "nadgrids");
const auto &towgs84 = getParamValue(step, "towgs84");
- if (!towgs84.empty()) {
+ // nadgrids has the priority over towgs84
+ if (!nadgrids.empty()) {
+ crs = BoundCRS::createFromNadgrids(crs, nadgrids);
+ } else if (!towgs84.empty()) {
std::vector<double> towgs84Values;
const auto tokens = split(towgs84, ',');
for (const auto &str : tokens) {
@@ -6687,11 +6709,6 @@ PROJStringParser::Private::buildBoundOrCompoundCRSIfNeeded(int iStep,
crs = BoundCRS::createFromTOWGS84(crs, towgs84Values);
}
- const auto &nadgrids = getParamValue(step, "nadgrids");
- if (!nadgrids.empty()) {
- crs = BoundCRS::createFromNadgrids(crs, nadgrids);
- }
-
const auto &geoidgrids = getParamValue(step, "geoidgrids");
if (!geoidgrids.empty()) {
auto vdatum =
@@ -7397,7 +7414,7 @@ PROJStringParser::createFromPROJString(const std::string &projString) {
d->globalParamValues_.clear();
d->projString_ = projString;
PROJStringSyntaxParser(projString, d->steps_, d->globalParamValues_,
- d->title_);
+ d->title_, false);
if (d->steps_.empty()) {
const auto &vunits = d->getGlobalParamValue("vunits");