aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@mines-paris.org>2019-01-09 16:24:16 +0100
committerGitHub <noreply@github.com>2019-01-09 16:24:16 +0100
commit5b75e5fdccc531f7b0e3dcd636fa1ff3500bb071 (patch)
treec718433341207fa688e85e145cf83ac4149491ab /src
parent11bc4783ca2c5fed8603d0c49f5aea102eca2432 (diff)
parenta6899c98a6455dc022bdd6785af3e528488422b8 (diff)
downloadPROJ-5b75e5fdccc531f7b0e3dcd636fa1ff3500bb071.tar.gz
PROJ-5b75e5fdccc531f7b0e3dcd636fa1ff3500bb071.zip
Merge pull request #1217 from rouault/remove_proj_5_crs_export
ISO19111: remove PROJ.5 specific format for CRS (refs #1214)
Diffstat (limited to 'src')
-rw-r--r--src/apps/projinfo.cpp41
-rw-r--r--src/iso19111/coordinateoperation.cpp64
-rw-r--r--src/iso19111/crs.cpp237
-rw-r--r--src/iso19111/io.cpp21
4 files changed, 148 insertions, 215 deletions
diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp
index b418bc57..446a1e9e 100644
--- a/src/apps/projinfo.cpp
+++ b/src/apps/projinfo.cpp
@@ -61,7 +61,6 @@ namespace { // anonymous namespace
struct OutputOptions {
bool quiet = false;
bool PROJ5 = false;
- bool PROJ4 = false;
bool WKT2_2018 = false;
bool WKT2_2018_SIMPLIFIED = false;
bool WKT2_2015 = false;
@@ -100,7 +99,7 @@ static void usage() {
<< std::endl;
std::cerr << std::endl;
std::cerr << "-o: formats is a comma separated combination of: "
- "all,default,PROJ4,PROJ,WKT_ALL,WKT2_2015,WKT2_2018,WKT1_GDAL,"
+ "all,default,PROJ,WKT_ALL,WKT2_2015,WKT2_2018,WKT1_GDAL,"
"WKT1_ESRI"
<< std::endl;
std::cerr << " Except 'all' and 'default', other format can be preceded "
@@ -256,32 +255,18 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj,
if (projStringExportable) {
if (outputOpt.PROJ5) {
try {
- if (!outputOpt.quiet) {
- std::cout << "PROJ string:" << std::endl;
- }
- std::cout << projStringExportable->exportToPROJString(
- PROJStringFormatter::create(
- PROJStringFormatter::Convention::PROJ_5,
- dbContext)
- .get())
- << std::endl;
- } catch (const std::exception &e) {
- std::cerr << "Error when exporting to PROJ string: " << e.what()
- << std::endl;
- }
- alreadyOutputed = true;
- }
-
- if (outputOpt.PROJ4) {
- try {
if (alreadyOutputed) {
std::cout << std::endl;
}
+ auto crs = nn_dynamic_pointer_cast<CRS>(obj);
if (!outputOpt.quiet) {
- std::cout << "PROJ.4 string:" << std::endl;
+ if( crs ) {
+ std::cout << "PROJ.4 string:" << std::endl;
+ } else {
+ std::cout << "PROJ string:" << std::endl;
+ }
}
- auto crs = nn_dynamic_pointer_cast<CRS>(obj);
std::shared_ptr<IPROJStringExportable> objToExport;
if (crs) {
objToExport =
@@ -295,7 +280,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj,
std::cout << objToExport->exportToPROJString(
PROJStringFormatter::create(
- PROJStringFormatter::Convention::PROJ_4,
+ PROJStringFormatter::Convention::PROJ_5,
dbContext)
.get())
<< std::endl;
@@ -651,23 +636,15 @@ int main(int argc, char **argv) {
for (auto format : formats) {
if (ci_equal(format, "all")) {
outputOpt.PROJ5 = true;
- outputOpt.PROJ4 = true;
outputOpt.WKT2_2018 = true;
outputOpt.WKT2_2015 = true;
outputOpt.WKT1_GDAL = true;
outputOpt.WKT1_ESRI = true;
} else if (ci_equal(format, "default")) {
outputOpt.PROJ5 = true;
- outputOpt.PROJ4 = false;
outputOpt.WKT2_2018 = false;
outputOpt.WKT2_2015 = true;
outputOpt.WKT1_GDAL = false;
- } else if (ci_equal(format, "PROJ4") ||
- ci_equal(format, "PROJ.4")) {
- outputOpt.PROJ4 = true;
- } else if (ci_equal(format, "-PROJ4") ||
- ci_equal(format, "-PROJ.4")) {
- outputOpt.PROJ4 = false;
} else if (ci_equal(format, "PROJ")) {
outputOpt.PROJ5 = true;
} else if (ci_equal(format, "-PROJ")) {
@@ -929,7 +906,7 @@ int main(int argc, char **argv) {
}
if (outputOpt.quiet &&
- (outputOpt.PROJ5 + outputOpt.PROJ4 + outputOpt.WKT2_2018 +
+ (outputOpt.PROJ5 + outputOpt.WKT2_2018 +
outputOpt.WKT2_2015 + outputOpt.WKT1_GDAL) != 1) {
std::cerr << "-q can only be used with a single output format"
<< std::endl;
diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp
index d00be93f..47f10392 100644
--- a/src/iso19111/coordinateoperation.cpp
+++ b/src/iso19111/coordinateoperation.cpp
@@ -5377,8 +5377,8 @@ bool Conversion::addWKTExtensionNode(io::WKTFormatter *formatter) const {
bool north = true;
if (l_method->getPrivate()->projMethodOverride_ == "etmerc" &&
!isUTM(zone, north)) {
- auto projFormatter = io::PROJStringFormatter::create(
- io::PROJStringFormatter::Convention::PROJ_4);
+ auto projFormatter = io::PROJStringFormatter::create();
+ projFormatter->setCRSExport(true);
projFormatter->setUseETMercForTMerc(true);
formatter->startNode(io::WKTConstants::EXTENSION, false);
formatter->addQuotedString("PROJ4");
@@ -5391,8 +5391,8 @@ bool Conversion::addWKTExtensionNode(io::WKTFormatter *formatter) const {
EPSG_CODE_METHOD_POPULAR_VISUALISATION_PSEUDO_MERCATOR ||
nameStr() == "Popular Visualisation Mercator") {
- auto projFormatter = io::PROJStringFormatter::create(
- io::PROJStringFormatter::Convention::PROJ_4);
+ auto projFormatter = io::PROJStringFormatter::create();
+ projFormatter->setCRSExport(true);
if (createPROJ4WebMercator(this, projFormatter.get())) {
formatter->startNode(io::WKTConstants::EXTENSION, false);
formatter->addQuotedString("PROJ4");
@@ -5401,8 +5401,8 @@ bool Conversion::addWKTExtensionNode(io::WKTFormatter *formatter) const {
return true;
}
} else if (starts_with(methodName, "PROJ ")) {
- auto projFormatter = io::PROJStringFormatter::create(
- io::PROJStringFormatter::Convention::PROJ_4);
+ auto projFormatter = io::PROJStringFormatter::create();
+ projFormatter->setCRSExport(true);
if (createPROJExtensionFromCustomProj(this, projFormatter.get(),
true)) {
formatter->startNode(io::WKTConstants::EXTENSION, false);
@@ -5413,8 +5413,8 @@ bool Conversion::addWKTExtensionNode(io::WKTFormatter *formatter) const {
}
} else if (methodName ==
PROJ_WKT2_NAME_METHOD_GEOSTATIONARY_SATELLITE_SWEEP_X) {
- auto projFormatter = io::PROJStringFormatter::create(
- io::PROJStringFormatter::Convention::PROJ_4);
+ auto projFormatter = io::PROJStringFormatter::create();
+ projFormatter->setCRSExport(true);
formatter->startNode(io::WKTConstants::EXTENSION, false);
formatter->addQuotedString("PROJ4");
_exportToPROJString(projFormatter.get());
@@ -5445,12 +5445,10 @@ void Conversion::_exportToPROJString(
const bool applySourceCRSModifiers =
!isZUnitConversion && !isAffineParametric &&
!isAxisOrderReversal(methodEPSGCode) && !isGeographicGeocentric;
- const bool applyTargetCRSModifiers = applySourceCRSModifiers;
+ bool applyTargetCRSModifiers = applySourceCRSModifiers;
auto l_sourceCRS = sourceCRS();
- if (l_sourceCRS && applySourceCRSModifiers &&
- formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_5) {
+ if (!formatter->getCRSExport() && l_sourceCRS && applySourceCRSModifiers) {
auto geogCRS =
dynamic_cast<const crs::GeographicCRS *>(l_sourceCRS.get());
if (geogCRS) {
@@ -5593,8 +5591,7 @@ void Conversion::_exportToPROJString(
EPSG_NAME_PARAMETER_LATITUDE_OF_NATURAL_ORIGIN);
}
// PROJ.4 specific hack for webmercator
- } else if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4 &&
+ } else if (formatter->getCRSExport() &&
methodEPSGCode ==
EPSG_CODE_METHOD_POPULAR_VISUALISATION_PSEUDO_MERCATOR) {
if (!createPROJ4WebMercator(this, formatter)) {
@@ -5605,14 +5602,15 @@ void Conversion::_exportToPROJString(
}
bConversionDone = true;
bEllipsoidParametersDone = true;
+ applyTargetCRSModifiers = false;
} else if (ci_equal(convName, "Popular Visualisation Mercator")) {
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4) {
+ if (formatter->getCRSExport()) {
if (!createPROJ4WebMercator(this, formatter)) {
throw io::FormattingException(concat(
"Cannot export ", convName,
" as PROJ.4 string outside of a ProjectedCRS context"));
}
+ applyTargetCRSModifiers = false;
} else {
formatter->addStep("webmerc");
if (l_sourceCRS) {
@@ -5717,8 +5715,7 @@ void Conversion::_exportToPROJString(
if (!bEllipsoidParametersDone) {
auto targetGeogCRS = l_targetCRS->extractGeographicCRS();
if (targetGeogCRS) {
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4) {
+ if (formatter->getCRSExport()) {
targetGeogCRS->addDatumInfoToPROJString(formatter);
} else {
targetGeogCRS->ellipsoid()->_exportToPROJString(formatter);
@@ -5737,13 +5734,10 @@ void Conversion::_exportToPROJString(
auto derivedGeographicCRS =
dynamic_cast<const crs::DerivedGeographicCRS *>(l_targetCRS.get());
if (derivedGeographicCRS) {
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_5) {
- auto geogCRS = derivedGeographicCRS->baseCRS();
- formatter->setOmitProjLongLatIfPossible(true);
- geogCRS->_exportToPROJString(formatter);
- formatter->setOmitProjLongLatIfPossible(false);
- }
+ auto baseGeodCRS = derivedGeographicCRS->baseCRS();
+ formatter->setOmitProjLongLatIfPossible(true);
+ baseGeodCRS->_exportToPROJString(formatter);
+ formatter->setOmitProjLongLatIfPossible(false);
}
}
}
@@ -11104,31 +11098,27 @@ CoordinateOperationFactory::Private::createOperations(
if (!targetProjExportable) {
throw InvalidOperation("Target CRS is not PROJ exportable");
}
- auto projFormatter = io::PROJStringFormatter::create(
- io::PROJStringFormatter::Convention::PROJ_4);
+ auto projFormatter = io::PROJStringFormatter::create();
+ projFormatter->setCRSExport(true);
projFormatter->startInversion();
sourceProjExportable->_exportToPROJString(projFormatter.get());
-
auto geogSrc =
dynamic_cast<const crs::GeographicCRS *>(sourceCRS.get());
if (geogSrc) {
- auto proj5Formatter = io::PROJStringFormatter::create(
- io::PROJStringFormatter::Convention::PROJ_5);
- geogSrc->addAngularUnitConvertAndAxisSwap(proj5Formatter.get());
- projFormatter->ingestPROJString(proj5Formatter->toString());
+ auto tmpFormatter = io::PROJStringFormatter::create();
+ geogSrc->addAngularUnitConvertAndAxisSwap(tmpFormatter.get());
+ projFormatter->ingestPROJString(tmpFormatter->toString());
}
projFormatter->stopInversion();
targetProjExportable->_exportToPROJString(projFormatter.get());
-
auto geogDst =
dynamic_cast<const crs::GeographicCRS *>(targetCRS.get());
if (geogDst) {
- auto proj5Formatter = io::PROJStringFormatter::create(
- io::PROJStringFormatter::Convention::PROJ_5);
- geogDst->addAngularUnitConvertAndAxisSwap(proj5Formatter.get());
- projFormatter->ingestPROJString(proj5Formatter->toString());
+ auto tmpFormatter = io::PROJStringFormatter::create();
+ geogDst->addAngularUnitConvertAndAxisSwap(tmpFormatter.get());
+ projFormatter->ingestPROJString(tmpFormatter->toString());
}
const auto PROJString = projFormatter->toString();
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp
index 190291de..6776093a 100644
--- a/src/iso19111/crs.cpp
+++ b/src/iso19111/crs.cpp
@@ -1142,13 +1142,11 @@ void GeodeticCRS::addGeocentricUnitConversionIntoPROJString(
const auto &unit = axisList[0]->unit();
if (!unit._isEquivalentTo(common::UnitOfMeasure::METRE,
util::IComparable::Criterion::EQUIVALENT)) {
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4) {
- io::FormattingException::Throw("GeodeticCRS::exportToPROJString(): "
- "non-meter unit not supported for "
- "PROJ.4");
+ if (formatter->getCRSExport()) {
+ io::FormattingException::Throw(
+ "GeodeticCRS::exportToPROJString() only "
+ "supports metre unit");
}
-
formatter->addStep("unitconvert");
formatter->addParam("xy_in", "m");
formatter->addParam("z_in", "m");
@@ -1164,8 +1162,7 @@ void GeodeticCRS::addGeocentricUnitConversionIntoPROJString(
const auto &toSI = unit.conversionToSI();
formatter->addParam("xy_out", toSI);
formatter->addParam("z_out", toSI);
- } else if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4) {
+ } else if (formatter->getCRSExport()) {
formatter->addParam("units", "m");
}
}
@@ -1177,14 +1174,11 @@ void GeodeticCRS::addGeocentricUnitConversionIntoPROJString(
void GeodeticCRS::_exportToPROJString(
io::PROJStringFormatter *formatter) const // throw(io::FormattingException)
{
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4) {
- const auto &extensionProj4 = CRS::getPrivate()->extensionProj4_;
- if (!extensionProj4.empty()) {
- formatter->ingestPROJString(extensionProj4);
- formatter->addNoDefs(false);
- return;
- }
+ const auto &extensionProj4 = CRS::getPrivate()->extensionProj4_;
+ if (!extensionProj4.empty()) {
+ formatter->ingestPROJString(extensionProj4);
+ formatter->addNoDefs(false);
+ return;
}
if (!isGeocentric()) {
@@ -1193,11 +1187,10 @@ void GeodeticCRS::_exportToPROJString(
"supports geocentric coordinate systems");
}
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4) {
- formatter->addStep("geocent");
- } else {
+ if (!formatter->getCRSExport()) {
formatter->addStep("cart");
+ } else {
+ formatter->addStep("geocent");
}
addDatumInfoToPROJString(formatter);
addGeocentricUnitConversionIntoPROJString(formatter);
@@ -1214,9 +1207,8 @@ void GeodeticCRS::addDatumInfoToPROJString(
bool datumWritten = false;
const auto &nadgrids = formatter->getHDatumExtension();
const auto &l_datum = datum();
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4 &&
- l_datum && TOWGS84Params.empty() && nadgrids.empty()) {
+ if (formatter->getCRSExport() && l_datum && TOWGS84Params.empty() &&
+ nadgrids.empty()) {
if (l_datum->_isEquivalentTo(
datum::GeodeticReferenceFrame::EPSG_6326.get(),
util::IComparable::Criterion::EQUIVALENT)) {
@@ -1857,57 +1849,53 @@ void GeographicCRS::addAngularUnitConvertAndAxisSwap(
io::PROJStringFormatter *formatter) const {
const auto &axisList = coordinateSystem()->axisList();
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_5) {
-
- formatter->addStep("unitconvert");
- formatter->addParam("xy_in", "rad");
- if (axisList.size() == 3 && !formatter->omitZUnitConversion()) {
- formatter->addParam("z_in", "m");
- }
- {
- const auto &unitHoriz = axisList[0]->unit();
- const auto projUnit = unitHoriz.exportToPROJString();
- if (projUnit.empty()) {
- formatter->addParam("xy_out", unitHoriz.conversionToSI());
- } else {
- formatter->addParam("xy_out", projUnit);
- }
+ formatter->addStep("unitconvert");
+ formatter->addParam("xy_in", "rad");
+ if (axisList.size() == 3 && !formatter->omitZUnitConversion()) {
+ formatter->addParam("z_in", "m");
+ }
+ {
+ const auto &unitHoriz = axisList[0]->unit();
+ const auto projUnit = unitHoriz.exportToPROJString();
+ if (projUnit.empty()) {
+ formatter->addParam("xy_out", unitHoriz.conversionToSI());
+ } else {
+ formatter->addParam("xy_out", projUnit);
}
- if (axisList.size() == 3 && !formatter->omitZUnitConversion()) {
- const auto &unitZ = axisList[2]->unit();
- auto projVUnit = unitZ.exportToPROJString();
- if (projVUnit.empty()) {
- formatter->addParam("z_out", unitZ.conversionToSI());
- } else {
- formatter->addParam("z_out", projVUnit);
- }
+ }
+ if (axisList.size() == 3 && !formatter->omitZUnitConversion()) {
+ const auto &unitZ = axisList[2]->unit();
+ auto projVUnit = unitZ.exportToPROJString();
+ if (projVUnit.empty()) {
+ formatter->addParam("z_out", unitZ.conversionToSI());
+ } else {
+ formatter->addParam("z_out", projVUnit);
}
+ }
- const char *order[2] = {nullptr, nullptr};
- const char *one = "1";
- const char *two = "2";
- for (int i = 0; i < 2; i++) {
- const auto &dir = axisList[i]->direction();
- if (&dir == &cs::AxisDirection::WEST) {
- order[i] = "-1";
- } else if (&dir == &cs::AxisDirection::EAST) {
- order[i] = one;
- } else if (&dir == &cs::AxisDirection::SOUTH) {
- order[i] = "-2";
- } else if (&dir == &cs::AxisDirection::NORTH) {
- order[i] = two;
- }
- }
- if (order[0] && order[1] && (order[0] != one || order[1] != two)) {
- formatter->addStep("axisswap");
- char orderStr[10];
- strcpy(orderStr, order[0]);
- strcat(orderStr, ",");
- strcat(orderStr, order[1]);
- formatter->addParam("order", orderStr);
+ const char *order[2] = {nullptr, nullptr};
+ const char *one = "1";
+ const char *two = "2";
+ for (int i = 0; i < 2; i++) {
+ const auto &dir = axisList[i]->direction();
+ if (&dir == &cs::AxisDirection::WEST) {
+ order[i] = "-1";
+ } else if (&dir == &cs::AxisDirection::EAST) {
+ order[i] = one;
+ } else if (&dir == &cs::AxisDirection::SOUTH) {
+ order[i] = "-2";
+ } else if (&dir == &cs::AxisDirection::NORTH) {
+ order[i] = two;
}
}
+ if (order[0] && order[1] && (order[0] != one || order[1] != two)) {
+ formatter->addStep("axisswap");
+ char orderStr[10];
+ strcpy(orderStr, order[0]);
+ strcat(orderStr, ",");
+ strcat(orderStr, order[1]);
+ formatter->addParam("order", orderStr);
+ }
}
//! @endcond
@@ -1917,14 +1905,11 @@ void GeographicCRS::addAngularUnitConvertAndAxisSwap(
void GeographicCRS::_exportToPROJString(
io::PROJStringFormatter *formatter) const // throw(io::FormattingException)
{
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4) {
- const auto &extensionProj4 = CRS::getPrivate()->extensionProj4_;
- if (!extensionProj4.empty()) {
- formatter->ingestPROJString(extensionProj4);
- formatter->addNoDefs(false);
- return;
- }
+ const auto &extensionProj4 = CRS::getPrivate()->extensionProj4_;
+ if (!extensionProj4.empty()) {
+ formatter->ingestPROJString(extensionProj4);
+ formatter->addNoDefs(false);
+ return;
}
if (!formatter->omitProjLongLatIfPossible() ||
@@ -1934,8 +1919,9 @@ void GeographicCRS::_exportToPROJString(
formatter->addStep("longlat");
addDatumInfoToPROJString(formatter);
}
-
- addAngularUnitConvertAndAxisSwap(formatter);
+ if (!formatter->getCRSExport()) {
+ addAngularUnitConvertAndAxisSwap(formatter);
+ }
}
//! @endcond
@@ -2107,20 +2093,17 @@ void VerticalCRS::addLinearUnitConvert(
io::PROJStringFormatter *formatter) const {
auto &axisList = coordinateSystem()->axisList();
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_5) {
- if (!axisList.empty()) {
- auto projUnit = axisList[0]->unit().exportToPROJString();
- if (axisList[0]->unit().conversionToSI() != 1.0) {
- formatter->addStep("unitconvert");
- formatter->addParam("z_in", "m");
- auto projVUnit = axisList[0]->unit().exportToPROJString();
- if (projVUnit.empty()) {
- formatter->addParam("z_out",
- axisList[0]->unit().conversionToSI());
- } else {
- formatter->addParam("z_out", projVUnit);
- }
+ if (!axisList.empty()) {
+ auto projUnit = axisList[0]->unit().exportToPROJString();
+ if (axisList[0]->unit().conversionToSI() != 1.0) {
+ formatter->addStep("unitconvert");
+ formatter->addParam("z_in", "m");
+ auto projVUnit = axisList[0]->unit().exportToPROJString();
+ if (projVUnit.empty()) {
+ formatter->addParam("z_out",
+ axisList[0]->unit().conversionToSI());
+ } else {
+ formatter->addParam("z_out", projVUnit);
}
}
}
@@ -2437,14 +2420,6 @@ void DerivedCRS::setDerivingConversionCRS() {
// ---------------------------------------------------------------------------
-void DerivedCRS::baseExportToPROJString(
- io::PROJStringFormatter *formatter) const // throw(io::FormattingException)
-{
- d->derivingConversion_->_exportToPROJString(formatter);
-}
-
-// ---------------------------------------------------------------------------
-
void DerivedCRS::baseExportToWKT(io::WKTFormatter *&formatter,
const std::string &keyword,
const std::string &baseKeyword) const {
@@ -2742,17 +2717,14 @@ void ProjectedCRS::_exportToWKT(io::WKTFormatter *formatter) const {
void ProjectedCRS::_exportToPROJString(
io::PROJStringFormatter *formatter) const // throw(io::FormattingException)
{
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4) {
- const auto &extensionProj4 = CRS::getPrivate()->extensionProj4_;
- if (!extensionProj4.empty()) {
- formatter->ingestPROJString(extensionProj4);
- formatter->addNoDefs(false);
- return;
- }
+ const auto &extensionProj4 = CRS::getPrivate()->extensionProj4_;
+ if (!extensionProj4.empty()) {
+ formatter->ingestPROJString(extensionProj4);
+ formatter->addNoDefs(false);
+ return;
}
- baseExportToPROJString(formatter);
+ derivingConversionRef()->_exportToPROJString(formatter);
}
// ---------------------------------------------------------------------------
@@ -2821,8 +2793,7 @@ void ProjectedCRS::addUnitConvertAndAxisSwap(io::PROJStringFormatter *formatter,
util::IComparable::Criterion::EQUIVALENT)) {
auto projUnit = unit.exportToPROJString();
const double toSI = unit.conversionToSI();
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_5) {
+ if (!formatter->getCRSExport()) {
formatter->addStep("unitconvert");
formatter->addParam("xy_in", "m");
formatter->addParam("z_in", "m");
@@ -2840,17 +2811,11 @@ void ProjectedCRS::addUnitConvertAndAxisSwap(io::PROJStringFormatter *formatter,
formatter->addParam("units", projUnit);
}
}
- } else if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4) {
- // could come from the hardcoded def of webmerc
- if (!formatter->hasParam("units")) {
- formatter->addParam("units", "m");
- }
+ } else if (formatter->getCRSExport()) {
+ formatter->addParam("units", "m");
}
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_5 &&
- !axisSpecFound) {
+ if (!axisSpecFound && !formatter->getCRSExport()) {
const auto &dir0 = axisList[0]->direction();
const auto &dir1 = axisList[1]->direction();
if (!(&dir0 == &cs::AxisDirection::EAST &&
@@ -3792,13 +3757,6 @@ void BoundCRS::_exportToWKT(io::WKTFormatter *formatter) const {
void BoundCRS::_exportToPROJString(
io::PROJStringFormatter *formatter) const // throw(io::FormattingException)
{
- if (formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_5) {
- io::FormattingException::Throw(
- "BoundCRS cannot be exported as a PROJ.5 string, but its baseCRS "
- "might");
- }
-
auto crs_exportable =
dynamic_cast<const io::IPROJStringExportable *>(d->baseCRS_.get());
if (!crs_exportable) {
@@ -4086,9 +4044,10 @@ void DerivedGeodeticCRS::_exportToWKT(io::WKTFormatter *formatter) const {
// ---------------------------------------------------------------------------
void DerivedGeodeticCRS::_exportToPROJString(
- io::PROJStringFormatter *formatter) const // throw(io::FormattingException)
+ io::PROJStringFormatter *) const // throw(io::FormattingException)
{
- baseExportToPROJString(formatter);
+ throw io::FormattingException(
+ "DerivedGeodeticCRS cannot be exported to PROJ string");
}
// ---------------------------------------------------------------------------
@@ -4223,9 +4182,10 @@ void DerivedGeographicCRS::_exportToWKT(io::WKTFormatter *formatter) const {
// ---------------------------------------------------------------------------
void DerivedGeographicCRS::_exportToPROJString(
- io::PROJStringFormatter *formatter) const // throw(io::FormattingException)
+ io::PROJStringFormatter *) const // throw(io::FormattingException)
{
- baseExportToPROJString(formatter);
+ throw io::FormattingException(
+ "DerivedGeographicCRS cannot be exported to PROJ string");
}
// ---------------------------------------------------------------------------
@@ -4377,14 +4337,6 @@ void DerivedProjectedCRS::_exportToWKT(io::WKTFormatter *formatter) const {
// ---------------------------------------------------------------------------
-void DerivedProjectedCRS::_exportToPROJString(
- io::PROJStringFormatter *formatter) const // throw(io::FormattingException)
-{
- baseExportToPROJString(formatter);
-}
-
-// ---------------------------------------------------------------------------
-
bool DerivedProjectedCRS::_isEquivalentTo(
const util::IComparable *other,
util::IComparable::Criterion criterion) const {
@@ -4792,9 +4744,10 @@ void DerivedVerticalCRS::_exportToWKT(io::WKTFormatter *formatter) const {
// ---------------------------------------------------------------------------
void DerivedVerticalCRS::_exportToPROJString(
- io::PROJStringFormatter *formatter) const // throw(io::FormattingException)
+ io::PROJStringFormatter *) const // throw(io::FormattingException)
{
- baseExportToPROJString(formatter);
+ throw io::FormattingException(
+ "DerivedVerticalCRS cannot be exported to PROJ string");
}
// ---------------------------------------------------------------------------
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp
index cfccd70f..13a8f236 100644
--- a/src/iso19111/io.cpp
+++ b/src/iso19111/io.cpp
@@ -4596,15 +4596,19 @@ IPROJStringExportable::~IPROJStringExportable() = default;
std::string IPROJStringExportable::exportToPROJString(
PROJStringFormatter *formatter) const {
+ const bool bIsCRS = dynamic_cast<const crs::CRS *>(this) != nullptr;
+ if (bIsCRS) {
+ formatter->setCRSExport(true);
+ }
_exportToPROJString(formatter);
- if (formatter->getAddNoDefs() &&
- formatter->convention() ==
- io::PROJStringFormatter::Convention::PROJ_4 &&
- dynamic_cast<const crs::CRS *>(this)) {
+ if (formatter->getAddNoDefs() && bIsCRS) {
if (!formatter->hasParam("no_defs")) {
formatter->addParam("no_defs");
}
}
+ if (bIsCRS) {
+ formatter->setCRSExport(false);
+ }
return formatter->toString();
}
//! @endcond
@@ -4673,6 +4677,7 @@ struct PROJStringFormatter::Private {
bool useETMercForTMercSet_ = false;
bool addNoDefs_ = true;
bool coordOperationOptimizations_ = false;
+ bool crsExport_ = false;
std::string result_{};
@@ -5311,6 +5316,14 @@ void PROJStringFormatter::ingestPROJString(
// ---------------------------------------------------------------------------
+void PROJStringFormatter::setCRSExport(bool b) { d->crsExport_ = b; }
+
+// ---------------------------------------------------------------------------
+
+bool PROJStringFormatter::getCRSExport() const { return d->crsExport_; }
+
+// ---------------------------------------------------------------------------
+
void PROJStringFormatter::startInversion() {
PROJStringFormatter::Private::InversionStackElt elt;
elt.startIter = d->steps_.end();