aboutsummaryrefslogtreecommitdiff
path: root/src/projinfo.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2018-12-07 19:53:48 +0100
committerEven Rouault <even.rouault@spatialys.com>2018-12-07 19:53:48 +0100
commit23127c01ad535902665a975da81e27c389bb7aeb (patch)
treed6cc90dfe1069425824de40fbe42342a1afca9bd /src/projinfo.cpp
parent706fac8bc70312f5729e2f3aeeb4f67ecb211b1d (diff)
parent29b522b4b80b43fe03cb1a955789676eec8051e7 (diff)
downloadPROJ-23127c01ad535902665a975da81e27c389bb7aeb.tar.gz
PROJ-23127c01ad535902665a975da81e27c389bb7aeb.zip
Merge remote-tracking branch 'rouault/gdalbarn'
Diffstat (limited to 'src/projinfo.cpp')
-rw-r--r--src/projinfo.cpp52
1 files changed, 41 insertions, 11 deletions
diff --git a/src/projinfo.cpp b/src/projinfo.cpp
index ddcc09da..d6fa37bc 100644
--- a/src/projinfo.cpp
+++ b/src/projinfo.cpp
@@ -37,6 +37,7 @@
#include "projects.h"
+#include <proj/common.hpp>
#include <proj/coordinateoperation.hpp>
#include <proj/crs.hpp>
#include <proj/io.hpp>
@@ -45,6 +46,7 @@
#include "proj/internal/internal.hpp" // for split
+using namespace NS_PROJ::common;
using namespace NS_PROJ::crs;
using namespace NS_PROJ::io;
using namespace NS_PROJ::metadata;
@@ -134,7 +136,8 @@ static std::string c_ify_string(const std::string &str) {
static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext,
const std::string &user_string,
bool kindIsCRS, const std::string &context,
- bool buildBoundCRSToWGS84) {
+ bool buildBoundCRSToWGS84,
+ bool allowPivots) {
BaseObjectPtr obj;
std::string l_user_string(user_string);
@@ -190,7 +193,8 @@ static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext,
if (buildBoundCRSToWGS84) {
auto crs = std::dynamic_pointer_cast<CRS>(obj);
if (crs) {
- obj = crs->createBoundCRSToWGS84IfPossible(dbContext).as_nullable();
+ obj = crs->createBoundCRSToWGS84IfPossible(dbContext, allowPivots)
+ .as_nullable();
}
}
@@ -200,7 +204,31 @@ static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext,
// ---------------------------------------------------------------------------
static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj,
- const OutputOptions &outputOpt) {
+ bool allowPivots, const OutputOptions &outputOpt) {
+
+ auto identified = dynamic_cast<const IdentifiedObject *>(obj.get());
+ if (!outputOpt.quiet && identified && identified->isDeprecated()) {
+ std::cout << "Warning: object is deprecated" << std::endl;
+ auto crs = dynamic_cast<const CRS *>(obj.get());
+ if (crs && dbContext) {
+ try {
+ auto list = crs->getNonDeprecated(NN_NO_CHECK(dbContext));
+ if (!list.empty()) {
+ std::cout << "Alternative non-deprecated CRS:" << std::endl;
+ }
+ for (const auto &altCRS : list) {
+ const auto &ids = altCRS->identifiers();
+ if (!ids.empty()) {
+ std::cout << " " << *(ids[0]->codeSpace()) << ":"
+ << ids[0]->code() << std::endl;
+ }
+ }
+ } catch (const std::exception &) {
+ }
+ }
+ std::cout << std::endl;
+ }
+
auto projStringExportable =
nn_dynamic_pointer_cast<IPROJStringExportable>(obj);
bool alreadyOutputed = false;
@@ -237,7 +265,8 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj,
if (crs) {
objToExport =
nn_dynamic_pointer_cast<IPROJStringExportable>(
- crs->createBoundCRSToWGS84IfPossible(dbContext));
+ crs->createBoundCRSToWGS84IfPossible(dbContext,
+ allowPivots));
}
if (!objToExport) {
objToExport = projStringExportable;
@@ -372,7 +401,8 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj,
std::shared_ptr<IWKTExportable> objToExport;
if (crs) {
objToExport = nn_dynamic_pointer_cast<IWKTExportable>(
- crs->createBoundCRSToWGS84IfPossible(dbContext));
+ crs->createBoundCRSToWGS84IfPossible(dbContext,
+ allowPivots));
}
if (!objToExport) {
objToExport = wktExportable;
@@ -480,7 +510,7 @@ static void outputOperations(
const std::string &authority, bool usePROJGridAlternatives,
bool showSuperseded, const OutputOptions &outputOpt, bool summary) {
auto sourceObj =
- buildObject(dbContext, sourceCRSStr, true, "source CRS", false);
+ buildObject(dbContext, sourceCRSStr, true, "source CRS", false, false);
auto sourceCRS = nn_dynamic_pointer_cast<CRS>(sourceObj);
if (!sourceCRS) {
std::cerr << "source CRS string is not a CRS" << std::endl;
@@ -488,7 +518,7 @@ static void outputOperations(
}
auto targetObj =
- buildObject(dbContext, targetCRSStr, true, "target CRS", false);
+ buildObject(dbContext, targetCRSStr, true, "target CRS", false, false);
auto targetCRS = nn_dynamic_pointer_cast<CRS>(targetObj);
if (!targetCRS) {
std::cerr << "target CRS string is not a CRS" << std::endl;
@@ -519,7 +549,7 @@ static void outputOperations(
std::exit(1);
}
if (outputOpt.quiet && !list.empty()) {
- outputObject(dbContext, list[0], outputOpt);
+ outputObject(dbContext, list[0], allowPivots, outputOpt);
return;
}
if (summary) {
@@ -545,7 +575,7 @@ static void outputOperations(
}
outputOperationSummary(op);
std::cout << std::endl;
- outputObject(dbContext, op, outputOpt);
+ outputObject(dbContext, op, allowPivots, outputOpt);
}
}
}
@@ -880,7 +910,7 @@ int main(int argc, char **argv) {
if (!user_string.empty()) {
auto obj(buildObject(dbContext, user_string, kindIsCRS, "input string",
- buildBoundCRSToWGS84));
+ buildBoundCRSToWGS84, allowPivots));
if (guessDialect) {
auto dialect = WKTParser().guessDialect(user_string);
std::cout << "Guessed WKT dialect: ";
@@ -897,7 +927,7 @@ int main(int argc, char **argv) {
}
std::cout << std::endl;
}
- outputObject(dbContext, obj, outputOpt);
+ outputObject(dbContext, obj, allowPivots, outputOpt);
if (identify) {
auto crs = dynamic_cast<CRS *>(obj.get());
if (crs) {