From da066800e59dcd5c3bf5e88ccca1bf1762de74dc Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 16 Dec 2020 16:32:13 +0100 Subject: cs2cs: add --no-ballpark and --accuracy options --- docs/source/apps/cs2cs.rst | 15 ++++++++++++++- src/apps/cs2cs.cpp | 33 +++++++++++++++++++++++++++++---- test/cli/testvarious | 12 ++++++++++++ test/cli/tv_out.dist | 4 ++++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/docs/source/apps/cs2cs.rst b/docs/source/apps/cs2cs.rst index 7df8890f..4706459a 100644 --- a/docs/source/apps/cs2cs.rst +++ b/docs/source/apps/cs2cs.rst @@ -13,7 +13,7 @@ Synopsis | **cs2cs** [**-eEfIlrstvwW** [args]] | [[--area ] | [--bbox ]] - | [--authority ] + | [--authority ] [--no-ballpark] [--accuracy ] | ([*+opt[=arg]* ...] [+to *+opt[=arg]* ...] | {source_crs} {target_crs}) | file ... @@ -166,6 +166,19 @@ The following control parameters can appear in any order: `south_lat` and `north_lat` in the [-90,90]. `west_long` is generally lower than `east_long`, except in the case where the area of interest crosses the antimeridian. +.. option:: --no-ballpark + + .. versionadded:: 8.0.0 + + Disallow any coordinate operation that is, or contains, a + :term:`Ballpark transformation` + +.. option:: --accuracy + + .. versionadded:: 8.0.0 + + Sets the minimum desired accuracy for candidate coordinate operations. + .. option:: --authority .. versionadded:: 8.0.0 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 #include #include +#include #include #include @@ -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 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/test/cli/testvarious b/test/cli/testvarious index 82be4992..a121393c 100755 --- a/test/cli/testvarious +++ b/test/cli/testvarious @@ -1021,6 +1021,18 @@ $EXE --authority EPSG -E +proj=latlong +datum=WGS84 +no_defs +to +init=epsg:6342 -105 40 EOF +echo "##############################################################" >> ${OUT} +echo "Test effect of --accuracy" >> ${OUT} +$EXE -E --accuracy 0.05 EPSG:4326 EPSG:4258 >> ${OUT} <> ${OUT} +echo "Test effect of --no-ballpark" >> ${OUT} +$EXE -E --no-ballpark EPSG:4267 EPSG:4258 >> ${OUT} <