diff options
| -rw-r--r-- | docs/source/apps/cs2cs.rst | 33 | ||||
| -rw-r--r-- | docs/source/development/reference/functions.rst | 14 | ||||
| -rw-r--r-- | src/4D_api.cpp | 29 | ||||
| -rw-r--r-- | src/apps/cs2cs.cpp | 20 | ||||
| -rwxr-xr-x | test/cli/testvarious | 13 | ||||
| -rw-r--r-- | test/cli/tv_out.dist | 7 |
6 files changed, 101 insertions, 15 deletions
diff --git a/docs/source/apps/cs2cs.rst b/docs/source/apps/cs2cs.rst index 7fe570d9..7df8890f 100644 --- a/docs/source/apps/cs2cs.rst +++ b/docs/source/apps/cs2cs.rst @@ -11,15 +11,11 @@ cs2cs Synopsis ******** - **cs2cs** [**-eEfIlrstvwW** [args]] - [[--area name_or_code] | [--bbox west_long,south_lat,east_long,north_lat]] - [*+opt[=arg]* ...] [+to *+opt[=arg]* ...] file ... - -or - - **cs2cs** [**-eEfIlrstvwW** [args]] [--area name_or_code] - [[--area name_or_code] | [--bbox west_long,south_lat,east_long,north_lat]] - {source_crs} {target_crs} file ... + | **cs2cs** [**-eEfIlrstvwW** [args]] + | [[--area <name_or_code>] | [--bbox <west_long,south_lat,east_long,north_lat>]] + | [--authority <name>] + | ([*+opt[=arg]* ...] [+to *+opt[=arg]* ...] | {source_crs} {target_crs}) + | file ... where {source_crs} or {target_crs} is one of the possibilities accepted by :c:func:`proj_create`, provided it expresses a CRS @@ -148,7 +144,7 @@ The following control parameters can appear in any order: Causes a listing of cartographic control parameters tested for and used by the program to be printed prior to input data. -.. option:: --area name_or_code +.. option:: --area <name_or_code> .. versionadded:: 8.0.0 @@ -158,7 +154,7 @@ The following control parameters can appear in any order: This option is mutually exclusive with :option:`--bbox`. -.. option:: --bbox west_long,south_lat,east_long,north_lat +.. option:: --bbox <west_long,south_lat,east_long,north_lat> .. versionadded:: 8.0.0 @@ -170,6 +166,21 @@ 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:: --authority <name> + + .. versionadded:: 8.0.0 + + This option can be used to restrict the authority of coordinate operations + looked up in the database. When not specified, coordinate + operations from any authority will be searched, with the restrictions set + in the ``authority_to_authority_preference`` database table related to the authority + of the source/target CRS themselves. + If authority is set to ``any``, then coordinate operations from any authority will be searched + If authority is a non-empty string different of ``any``, then coordinate operations + will be searched only in that authority namespace (e.g ``EPSG``). + + This option is mutually exclusive with :option:`--bbox`. + .. only:: man The *+opt* run-line arguments are associated with cartographic diff --git a/docs/source/development/reference/functions.rst b/docs/source/development/reference/functions.rst index cc29743c..32902916 100644 --- a/docs/source/development/reference/functions.rst +++ b/docs/source/development/reference/functions.rst @@ -182,7 +182,19 @@ paragraph for more details. This is the same as :c:func:`proj_create_crs_to_crs` except that the source and target CRS are passed as PJ* objects which must of the CRS variety. - :param `options`: should be set to NULL currently. + :param `options`: a list of NUL terminated options, or NULL. + + The list of supported options is: + + - AUTHORITY=name: to restrict the authority of coordinate operations + looked up in the database. When not specified, coordinate + ``operations from any authority`` will be searched, with the restrictions set + in the authority_to_authority_preference database table related to the authority + of the source/target CRS themselves. + If authority is set to "any", then coordinate operations from any authority will be searched + If authority is a non-empty string different of ``any``, then coordinate operations + will be searched only in that authority namespace (e.g ``EPSG``). + .. doxygenfunction:: proj_normalize_for_visualization :project: doxygen_api diff --git a/src/4D_api.cpp b/src/4D_api.cpp index 9231a7ed..d6eb901d 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -1260,8 +1260,20 @@ std::vector<CoordOperation> pj_create_prepared_operations(PJ_CONTEXT *ctx, } } +// --------------------------------------------------------------------------- + +//! @cond Doxygen_Suppress +static const char *getOptionValue(const char *option, + const char *keyWithEqual) noexcept { + if (ci_starts_with(option, keyWithEqual)) { + return option + strlen(keyWithEqual); + } + return nullptr; +} +//! @endcond + /*****************************************************************************/ -PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, const PJ *target_crs, PJ_AREA *area, const char* const *) { +PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, const PJ *target_crs, PJ_AREA *area, const char* const * options) { /****************************************************************************** Create a transformation pipeline between two known coordinate reference systems. @@ -1273,7 +1285,20 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons ctx = pj_get_default_ctx(); } - auto operation_ctx = proj_create_operation_factory_context(ctx, nullptr); + const char* authority = nullptr; + for (auto iter = options; iter && iter[0]; ++iter) { + const char *value; + if ((value = getOptionValue(*iter, "AUTHORITY="))) { + authority = value; + } else { + std::string msg("Unknown option :"); + msg += *iter; + ctx->logger(ctx->logger_app_data, PJ_LOG_ERROR, msg.c_str()); + return nullptr; + } + } + + auto operation_ctx = proj_create_operation_factory_context(ctx, authority); if( !operation_ctx ) { return nullptr; } diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp index dd65baf4..409a5ef3 100644 --- a/src/apps/cs2cs.cpp +++ b/src/apps/cs2cs.cpp @@ -77,6 +77,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" " [+opt[=arg] ...] [+to +opt[=arg] ...] [file ...]\n"; static double (*informat)(const char *, @@ -372,6 +373,7 @@ int main(int argc, char **argv) { ExtentPtr bboxFilter; std::string area; + const char* authority = nullptr; /* process run line arguments */ while (--argc > 0) { /* collect run line arguments */ @@ -410,6 +412,15 @@ int main(int argc, char **argv) { std::exit(1); } } + else if (strcmp(*argv, "--authority") == 0 ) { + ++argv; + --argc; + if( argc == 0 ) { + emess(1, "missing argument for --authority"); + std::exit(1); + } + authority = *argv; + } else if (**argv == '-') { for (arg = *argv;;) { switch (*++arg) { @@ -761,8 +772,15 @@ int main(int argc, char **argv) { } } + std::string authorityOption; /* keep this variable in this outer scope ! */ + const char* options[2] = { nullptr, nullptr }; + if( authority ) { + authorityOption = "AUTHORITY="; + authorityOption += authority; + options[0] = authorityOption.data(); + } transformation = proj_create_crs_to_crs_from_pj(nullptr, src, dst, - pj_area, nullptr); + pj_area, options); proj_destroy(src); proj_destroy(dst); diff --git a/test/cli/testvarious b/test/cli/testvarious index 292ee316..82be4992 100755 --- a/test/cli/testvarious +++ b/test/cli/testvarious @@ -1009,6 +1009,19 @@ $EXE -f %.3f EPSG:4686 EPSG:6247 -E >> ${OUT} <<EOF 4.8 -74.25 EOF +echo "##############################################################" >> ${OUT} +echo "Test effect of --authority (https://github.com/OSGeo/PROJ/issues/2442)" >> ${OUT} +echo "This test might be a bit fragile if proj.db content changes" >> ${OUT} +echo "The first result should use the 'WGS_1984_(ITRF08)_To_NAD_1983_2011' (ESRI:108363) operation" >> ${OUT} +echo "and the second one a no-op" >> ${OUT} +$EXE -E +proj=latlong +datum=WGS84 +no_defs +to +init=epsg:6342 >> ${OUT} <<EOF +-105 40 +EOF +$EXE --authority EPSG -E +proj=latlong +datum=WGS84 +no_defs +to +init=epsg:6342 >> ${OUT} <<EOF +-105 40 +EOF + + # Done! # do 'diff' with distribution results echo "diff ${OUT} with ${OUT}.dist" diff --git a/test/cli/tv_out.dist b/test/cli/tv_out.dist index 70b2ab6e..fe1aa452 100644 --- a/test/cli/tv_out.dist +++ b/test/cli/tv_out.dist @@ -485,3 +485,10 @@ Test EPSG:xxxx EPSG:yyyy filename ############################################################## Test Colombia Urban 4.8 -74.25 122543.174 80859.033 0.000 +############################################################## +Test effect of --authority (https://github.com/OSGeo/PROJ/issues/2442) +This test might be a bit fragile if proj.db content changes +The first result should use the 'WGS_1984_(ITRF08)_To_NAD_1983_2011' (ESRI:108363) operation +and the second one a no-op +-105 40 500000.86 4427756.50 0.00 +-105 40 500000.00 4427757.22 0.00 |
