aboutsummaryrefslogtreecommitdiff
path: root/src/apps
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-12-16 21:02:37 +0100
committerGitHub <noreply@github.com>2020-12-16 21:02:37 +0100
commit7766b1aad7328b94b7ecc9afe0ad7e874c989ad3 (patch)
treeed39359433f8004f03d0e4bef02b0cc41e62f0d5 /src/apps
parent1a84a71349c31740b4a525971cf56c899dda858e (diff)
parentda066800e59dcd5c3bf5e88ccca1bf1762de74dc (diff)
downloadPROJ-7766b1aad7328b94b7ecc9afe0ad7e874c989ad3.tar.gz
PROJ-7766b1aad7328b94b7ecc9afe0ad7e874c989ad3.zip
Merge pull request #2488 from rouault/crs_to_crs_improved_filtering
Improved coordinate operation filtering
Diffstat (limited to 'src/apps')
-rw-r--r--src/apps/cs2cs.cpp33
-rw-r--r--src/apps/projinfo.cpp27
2 files changed, 47 insertions, 13 deletions
diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp
index 409a5ef3..5542a282 100644
--- a/src/apps/cs2cs.cpp
+++ b/src/apps/cs2cs.cpp
@@ -38,6 +38,7 @@
#include <cassert>
#include <iostream>
#include <string>
+#include <vector>
#include <proj/io.hpp>
#include <proj/metadata.hpp>
@@ -77,7 +78,7 @@ static const char *oterr = "*\t*"; /* output line for unprojectable input */
static const char *usage =
"%s\nusage: %s [-dDeEfIlrstvwW [args]]\n"
" [[--area name_or_code] | [--bbox west_long,south_lat,east_long,north_lat]]\n"
- " [--authority {name}]\n"
+ " [--authority {name}] [--accuracy {accuracy}] [--no-ballpark]\n"
" [+opt[=arg] ...] [+to +opt[=arg] ...] [file ...]\n";
static double (*informat)(const char *,
@@ -374,6 +375,8 @@ int main(int argc, char **argv) {
ExtentPtr bboxFilter;
std::string area;
const char* authority = nullptr;
+ double accuracy = -1;
+ bool allowBallpark = true;
/* process run line arguments */
while (--argc > 0) { /* collect run line arguments */
@@ -412,6 +415,15 @@ int main(int argc, char **argv) {
std::exit(1);
}
}
+ else if (strcmp(*argv, "--accuracy") == 0 ) {
+ ++argv;
+ --argc;
+ if( argc == 0 ) {
+ emess(1, "missing argument for --accuracy");
+ std::exit(1);
+ }
+ accuracy = c_locale_stod(*argv);
+ }
else if (strcmp(*argv, "--authority") == 0 ) {
++argv;
--argc;
@@ -421,6 +433,9 @@ int main(int argc, char **argv) {
}
authority = *argv;
}
+ else if (strcmp(*argv, "--no-ballpark") == 0 ) {
+ allowBallpark = false;
+ }
else if (**argv == '-') {
for (arg = *argv;;) {
switch (*++arg) {
@@ -773,14 +788,24 @@ int main(int argc, char **argv) {
}
std::string authorityOption; /* keep this variable in this outer scope ! */
- const char* options[2] = { nullptr, nullptr };
+ std::string accuracyOption; /* keep this variable in this outer scope ! */
+ std::vector<const char*> options;
if( authority ) {
authorityOption = "AUTHORITY=";
authorityOption += authority;
- options[0] = authorityOption.data();
+ options.push_back(authorityOption.data());
+ }
+ if( accuracy >= 0 ) {
+ accuracyOption = "ACCURACY=";
+ accuracyOption += toString(accuracy);
+ options.push_back(accuracyOption.data());
+ }
+ if( !allowBallpark ) {
+ options.push_back("ALLOW_BALLPARK=NO");
}
+ options.push_back(nullptr);
transformation = proj_create_crs_to_crs_from_pj(nullptr, src, dst,
- pj_area, options);
+ pj_area, options.data());
proj_destroy(src);
proj_destroy(dst);
diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp
index da885fbb..8d389019 100644
--- a/src/apps/projinfo.cpp
+++ b/src/apps/projinfo.cpp
@@ -95,7 +95,9 @@ static void usage() {
<< std::endl
<< " [--pivot-crs always|if_no_direct_transformation|"
<< "never|{auth:code[,auth:code]*}]" << std::endl
- << " [--show-superseded] [--hide-ballpark]" << std::endl
+ << " [--show-superseded] [--hide-ballpark] "
+ "[--accuracy {accuracy}]"
+ << std::endl
<< " [--allow-ellipsoidal-height-as-vertical-crs]"
<< std::endl
<< " [--boundcrs-to-wgs84]" << std::endl
@@ -672,8 +674,8 @@ static void outputOperations(
CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS,
const std::vector<std::pair<std::string, std::string>> &pivots,
const std::string &authority, bool usePROJGridAlternatives,
- bool showSuperseded, bool promoteTo3D, const OutputOptions &outputOpt,
- bool summary) {
+ bool showSuperseded, bool promoteTo3D, double minimumAccuracy,
+ const OutputOptions &outputOpt, bool summary) {
auto sourceObj =
buildObject(dbContext, sourceCRSStr, "crs", "source CRS", false,
CoordinateOperationContext::IntermediateCRSUse::NEVER,
@@ -715,6 +717,9 @@ static void outputOperations(
ctxt->setUsePROJAlternativeGridNames(usePROJGridAlternatives);
ctxt->setDiscardSuperseded(!showSuperseded);
ctxt->setAllowBallparkTransformations(outputOpt.ballparkAllowed);
+ if (minimumAccuracy >= 0) {
+ ctxt->setDesiredAccuracy(minimumAccuracy);
+ }
list = CoordinateOperationFactory::create()->createOperations(
nnSourceCRS, nnTargetCRS, ctxt);
if (!spatialCriterionExplicitlySpecified &&
@@ -819,6 +824,7 @@ int main(int argc, char **argv) {
bool identify = false;
bool showSuperseded = false;
bool promoteTo3D = false;
+ double minimumAccuracy = -1;
for (int i = 1; i < argc; i++) {
std::string arg(argv[i]);
@@ -934,6 +940,9 @@ int main(int argc, char **argv) {
<< ", " << e.what() << std::endl;
usage();
}
+ } else if (arg == "--accuracy" && i + 1 < argc) {
+ i++;
+ minimumAccuracy = c_locale_stod(argv[i]);
} else if (arg == "--area" && i + 1 < argc) {
i++;
area = argv[i];
@@ -1338,12 +1347,12 @@ int main(int argc, char **argv) {
}
try {
- outputOperations(dbContext, sourceCRSStr, targetCRSStr, bboxFilter,
- spatialCriterion,
- spatialCriterionExplicitlySpecified, crsExtentUse,
- gridAvailabilityUse, allowUseIntermediateCRS,
- pivots, authority, usePROJGridAlternatives,
- showSuperseded, promoteTo3D, outputOpt, summary);
+ outputOperations(
+ dbContext, sourceCRSStr, targetCRSStr, bboxFilter,
+ spatialCriterion, spatialCriterionExplicitlySpecified,
+ crsExtentUse, gridAvailabilityUse, allowUseIntermediateCRS,
+ pivots, authority, usePROJGridAlternatives, showSuperseded,
+ promoteTo3D, minimumAccuracy, outputOpt, summary);
} catch (const std::exception &e) {
std::cerr << "outputOperations() failed with: " << e.what()
<< std::endl;