aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apply_gridshift.cpp9
-rw-r--r--src/apps/cs2cs.cpp2
-rw-r--r--src/iso19111/coordinateoperation.cpp2
-rw-r--r--src/iso19111/crs.cpp42
-rw-r--r--src/iso19111/io.cpp56
-rw-r--r--src/malloc.cpp7
-rw-r--r--src/proj.h2
7 files changed, 75 insertions, 45 deletions
diff --git a/src/apply_gridshift.cpp b/src/apply_gridshift.cpp
index fcd9fa01..e6c7b2b1 100644
--- a/src/apply_gridshift.cpp
+++ b/src/apply_gridshift.cpp
@@ -344,7 +344,14 @@ PJ_LP proj_hgrid_apply(PJ *P, PJ_LP lp, PJ_DIRECTION direction) {
ct = find_ctable(P->ctx, lp, P->gridlist_count, P->gridlist);
if (ct == nullptr || ct->cvs == nullptr) {
- pj_ctx_set_errno( P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
+ if( P->gridlist_count == 1 &&
+ strcmp(P->gridlist[0]->gridname, "null") == 0) {
+ // TODO: remove this particular case that is put there just to be
+ // able to handle longitudes outside of -180,180
+ out = lp;
+ } else {
+ pj_ctx_set_errno( P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
+ }
return out;
}
diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp
index 20e5e73c..3099c3e8 100644
--- a/src/apps/cs2cs.cpp
+++ b/src/apps/cs2cs.cpp
@@ -645,7 +645,7 @@ int main(int argc, char **argv) {
proj_destroy(transformation);
- pj_deallocate_grids();
+ proj_cleanup();
exit(0); /* normal completion */
}
diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp
index dc700445..e9524163 100644
--- a/src/iso19111/coordinateoperation.cpp
+++ b/src/iso19111/coordinateoperation.cpp
@@ -12064,7 +12064,7 @@ CoordinateOperationFactory::Private::createOperations(
}
auto projFormatter = io::PROJStringFormatter::create();
projFormatter->setCRSExport(true);
- projFormatter->setDropEarlyBindingsTerms(true);
+ projFormatter->setLegacyCRSToCRSContext(true);
projFormatter->startInversion();
sourceProjExportable->_exportToPROJString(projFormatter.get());
auto geogSrc =
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp
index b9694ba2..60b316f1 100644
--- a/src/iso19111/crs.cpp
+++ b/src/iso19111/crs.cpp
@@ -1308,7 +1308,7 @@ void GeodeticCRS::addDatumInfoToPROJString(
const auto &nadgrids = formatter->getHDatumExtension();
const auto &l_datum = datum();
if (formatter->getCRSExport() && l_datum && TOWGS84Params.empty() &&
- nadgrids.empty() && !formatter->getDropEarlyBindingsTerms()) {
+ nadgrids.empty()) {
if (l_datum->_isEquivalentTo(
datum::GeodeticReferenceFrame::EPSG_6326.get(),
util::IComparable::Criterion::EQUIVALENT)) {
@@ -1323,7 +1323,12 @@ void GeodeticCRS::addDatumInfoToPROJString(
datum::GeodeticReferenceFrame::EPSG_6269.get(),
util::IComparable::Criterion::EQUIVALENT)) {
datumWritten = true;
- formatter->addParam("datum", "NAD83");
+ if (formatter->getLegacyCRSToCRSContext()) {
+ // We do not want datum=NAD83 to cause a useless towgs84=0,0,0
+ formatter->addParam("ellps", "GRS80");
+ } else {
+ formatter->addParam("datum", "NAD83");
+ }
}
}
if (!datumWritten) {
@@ -2083,8 +2088,31 @@ void GeographicCRS::_exportToPROJString(
primeMeridian()->longitude().getSIValue() != 0.0 ||
!formatter->getTOWGS84Parameters().empty() ||
!formatter->getHDatumExtension().empty()) {
+
formatter->addStep("longlat");
- addDatumInfoToPROJString(formatter);
+ bool done = false;
+ if (formatter->getLegacyCRSToCRSContext() &&
+ formatter->getHDatumExtension().empty() &&
+ formatter->getTOWGS84Parameters().empty()) {
+ const auto &l_datum = datum();
+ if (l_datum &&
+ l_datum->_isEquivalentTo(
+ datum::GeodeticReferenceFrame::EPSG_6326.get(),
+ util::IComparable::Criterion::EQUIVALENT)) {
+ done = true;
+ formatter->addParam("ellps", "WGS84");
+ } else if (l_datum &&
+ l_datum->_isEquivalentTo(
+ datum::GeodeticReferenceFrame::EPSG_6269.get(),
+ util::IComparable::Criterion::EQUIVALENT)) {
+ done = true;
+ // We do not want datum=NAD83 to cause a useless towgs84=0,0,0
+ formatter->addParam("ellps", "GRS80");
+ }
+ }
+ if (!done) {
+ addDatumInfoToPROJString(formatter);
+ }
}
if (!formatter->getCRSExport()) {
addAngularUnitConvertAndAxisSwap(formatter);
@@ -3132,7 +3160,8 @@ void ProjectedCRS::addUnitConvertAndAxisSwap(io::PROJStringFormatter *formatter,
formatter->addParam("units", projUnit);
}
}
- } else if (formatter->getCRSExport()) {
+ } else if (formatter->getCRSExport() &&
+ !formatter->getLegacyCRSToCRSContext()) {
formatter->addParam("units", "m");
}
@@ -4143,11 +4172,6 @@ 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 f4d93ef4..20a90946 100644
--- a/src/iso19111/io.cpp
+++ b/src/iso19111/io.cpp
@@ -6145,7 +6145,7 @@ struct PROJStringFormatter::Private {
bool addNoDefs_ = true;
bool coordOperationOptimizations_ = false;
bool crsExport_ = false;
- bool dropEarlyBindingsTerms_ = false;
+ bool legacyCRSToCRSContext_ = false;
std::string result_{};
@@ -6723,7 +6723,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, bool dropEarlyBindingsTerms) {
+ std::string &title) {
const char *c_str = projString.c_str();
std::vector<std::string> tokens;
@@ -6811,27 +6811,14 @@ PROJStringSyntaxParser(const std::string &projString, std::vector<Step> &steps,
} else if (word != "step") {
const auto pos = word.find('=');
auto key = word.substr(0, pos);
- if (!(dropEarlyBindingsTerms &&
- (key == "towgs84" || key == "nadgrids" ||
- key == "geoidgrids"))) {
- auto pair = (pos != std::string::npos)
- ? Step::KeyValue(key, word.substr(pos + 1))
- : Step::KeyValue(key);
- if (dropEarlyBindingsTerms && key == "datum") {
- const auto datums = pj_get_datums_ref();
- for (int i = 0; datums[i].id != nullptr; i++) {
- if (pair.value == datums[i].id) {
- pair.key = "ellps";
- pair.value = datums[i].ellipse_id;
- break;
- }
- }
- }
- if (steps.empty()) {
- globalParamValues.push_back(pair);
- } else {
- steps.back().paramValues.push_back(pair);
- }
+
+ 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);
}
}
}
@@ -6906,8 +6893,7 @@ void PROJStringFormatter::ingestPROJString(
{
std::vector<Step> steps;
std::string title;
- PROJStringSyntaxParser(str, steps, d->globalParamValues_, title,
- d->dropEarlyBindingsTerms_);
+ PROJStringSyntaxParser(str, steps, d->globalParamValues_, title);
d->steps_.insert(d->steps_.end(), steps.begin(), steps.end());
}
@@ -7175,14 +7161,14 @@ bool PROJStringFormatter::omitZUnitConversion() const {
// ---------------------------------------------------------------------------
-void PROJStringFormatter::setDropEarlyBindingsTerms(bool drop) {
- d->dropEarlyBindingsTerms_ = drop;
+void PROJStringFormatter::setLegacyCRSToCRSContext(bool legacyContext) {
+ d->legacyCRSToCRSContext_ = legacyContext;
}
// ---------------------------------------------------------------------------
-bool PROJStringFormatter::getDropEarlyBindingsTerms() const {
- return d->dropEarlyBindingsTerms_;
+bool PROJStringFormatter::getLegacyCRSToCRSContext() const {
+ return d->legacyCRSToCRSContext_;
}
// ---------------------------------------------------------------------------
@@ -8269,6 +8255,7 @@ CRSNNPtr PROJStringParser::Private::buildProjectedCRS(
}
auto axisType = AxisType::REGULAR;
+ bool bWebMercator = false;
if (step.name == "tmerc" &&
((getParamValue(step, "axis") == "wsu" && iAxisSwap < 0) ||
@@ -8351,8 +8338,7 @@ CRSNNPtr PROJStringParser::Private::buildProjectedCRS(
}
}
if (getNumericValue(getParamValue(step, "a")) == 6378137) {
- return createPseudoMercator(PropertyMap().set(
- IdentifiedObject::NAME_KEY, "WGS 84 / Pseudo-Mercator"));
+ bWebMercator = true;
}
} else if (hasParamValue(step, "lat_ts")) {
mapping = getMapping(EPSG_CODE_METHOD_MERCATOR_VARIANT_B);
@@ -8613,7 +8599,11 @@ CRSNNPtr PROJStringParser::Private::buildProjectedCRS(
props.set("IMPLICIT_CS", true);
- CRSNNPtr crs = ProjectedCRS::create(props, geogCRS, NN_NO_CHECK(conv), cs);
+ CRSNNPtr crs =
+ bWebMercator
+ ? createPseudoMercator(props.set(IdentifiedObject::NAME_KEY,
+ "WGS 84 / Pseudo-Mercator"))
+ : ProjectedCRS::create(props, geogCRS, NN_NO_CHECK(conv), cs);
if (!hasParamValue(step, "geoidgrids") &&
(hasParamValue(step, "vunits") || hasParamValue(step, "vto_meter"))) {
@@ -8671,7 +8661,7 @@ PROJStringParser::createFromPROJString(const std::string &projString) {
d->globalParamValues_.clear();
d->projString_ = projString;
PROJStringSyntaxParser(projString, d->steps_, d->globalParamValues_,
- d->title_, false);
+ d->title_);
if (d->steps_.empty()) {
const auto &vunits = d->getGlobalParamValue("vunits");
diff --git a/src/malloc.cpp b/src/malloc.cpp
index 817f8f20..393437e3 100644
--- a/src/malloc.cpp
+++ b/src/malloc.cpp
@@ -255,3 +255,10 @@ PJ *pj_default_destructor (PJ *P, int errlev) { /* Destructor */
delete P;
return nullptr;
}
+
+/*****************************************************************************/
+void proj_cleanup() {
+/*****************************************************************************/
+ pj_clear_initcache();
+ pj_deallocate_grids();
+}
diff --git a/src/proj.h b/src/proj.h
index 57fb3940..14d315b5 100644
--- a/src/proj.h
+++ b/src/proj.h
@@ -458,6 +458,8 @@ double PROJ_DLL proj_todeg (double angle_in_radians);
double PROJ_DLL proj_dmstor(const char *is, char **rs);
char PROJ_DLL * proj_rtodms(char *s, double r, int pos, int neg);
+void PROJ_DLL proj_cleanup(void);
+
/*! @endcond */
/* ------------------------------------------------------------------------- */