diff options
| author | Kristian Evers <kristianevers@gmail.com> | 2020-11-10 14:08:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-10 14:08:30 +0100 |
| commit | af342bf74cd154b653a0f9d931d4ca17001650b9 (patch) | |
| tree | 0385cc3b07d2b34b91a05f5fa95071178caf828b | |
| parent | bcfb1940602bf4da9be9e7e8423645ef8c627633 (diff) | |
| download | PROJ-af342bf74cd154b653a0f9d931d4ca17001650b9.tar.gz PROJ-af342bf74cd154b653a0f9d931d4ca17001650b9.zip | |
Allow cct to instantiate operations via object codes or names (#2419)
Running cct like
cct EPSG:8366
or
cct "ITRF2014 to ETRF2014 (1)"
is now possible.
| -rw-r--r-- | docs/source/apps/cct.rst | 27 | ||||
| -rw-r--r-- | src/apps/cct.cpp | 36 | ||||
| -rwxr-xr-x | test/cli/testcct | 12 | ||||
| -rw-r--r-- | test/cli/testcct_out.dist | 7 |
4 files changed, 78 insertions, 4 deletions
diff --git a/docs/source/apps/cct.rst b/docs/source/apps/cct.rst index 1d2aef20..df81c571 100644 --- a/docs/source/apps/cct.rst +++ b/docs/source/apps/cct.rst @@ -15,6 +15,33 @@ Synopsis **cct** [**-cIostvz** [args]] *+opt[=arg]* ... file ... +or + + **cct** [**-cIostvz** [args]] {operation_reference} file ... + +Where {operation_reference} is one of the possibilities accepted +by :c:func:`proj_create`, provided it expresses a coordinate operation + +- a proj-string, + - a WKT string, + - an object code (like "EPSG:1671" "urn:ogc:def:coordinateOperation:EPSG::1671"), + - an object name. e.g "ITRF2014 to ETRF2014 (1)". In that case as + uniqueness is not guaranteed, heuristics are applied to determine the appropriate best match. + - a OGC URN combining references for concatenated operations + (e.g. "urn:ogc:def:coordinateOperation,coordinateOperation:EPSG::3895,coordinateOperation:EPSG::1618") + - a PROJJSON string. The jsonschema is at https://proj.org/schemas/v0.2/projjson.schema.json + + .. versionadded:: 8.0.0 + + .. note:: + + Before version 8.0.0 only proj-strings could be used to instantiate + operations in :program:`cct`. + + + + + Description *********** diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp index f7413872..4de3cf8e 100644 --- a/src/apps/cct.cpp +++ b/src/apps/cct.cpp @@ -77,6 +77,7 @@ Thomas Knudsen, thokn@sdfe.dk, 2016-05-25/2017-10-26 #include <stdlib.h> #include <string.h> #include <stdarg.h> +#include <iostream> #include "proj.h" #include "proj_internal.h" @@ -193,9 +194,8 @@ static void print(PJ_LOG_LEVEL log_level, const char *fmt, ...) { free( msg_buf ); } - int main(int argc, char **argv) { - PJ *P; + PJ *P = nullptr; PJ_COORD point; PJ_PROJ_INFO info; OPTARGS *o; @@ -292,8 +292,36 @@ int main(int argc, char **argv) { } /* Setup transformation */ - P = proj_create_argv (nullptr, o->pargc, o->pargv); - if ((nullptr==P) || (0==o->pargc)) { + if (o-> pargc == 0 && o->fargc > 0) { + /* Assume we got a auth:code combination */ + std::string input(o->fargv[0]); + auto n = input.find(":"); + if (n > 0) { + std::string auth = input.substr(0,n); + std::string code = input.substr(n+1, input.length()); + P = proj_create_from_database( + nullptr, auth.c_str(), code.c_str(), PJ_CATEGORY_COORDINATE_OPERATION, 0, nullptr + ); + } + if( P == nullptr ) { + /* if we didn't get a auth:code combo we try to see if the input matches */ + /* anything else */ + P = proj_create(nullptr, o->fargv[0]); + } + + /* If instantiating operation without +-options optargpm thinks the input is */ + /* a file, hence we move all o->fargv entries one place closer to the start */ + /* of the array. This effectively overwrites the input and only leaves a list */ + /* of files in o->fargv. */ + o->fargc = o->fargc-1; + for (int j=0; j < o->fargc; j++) { + o->fargv[j] = o->fargv[j+1]; + } + } else { + P = proj_create_argv (nullptr, o->pargc, o->pargv); + } + + if (nullptr==P) { print (PJ_LOG_ERROR, "%s: Bad transformation arguments - (%s)\n '%s -h' for help", o->progname, pj_strerrno (proj_errno(P)), o->progname); free (o); diff --git a/test/cli/testcct b/test/cli/testcct index 3fb0dd95..bbe698bd 100755 --- a/test/cli/testcct +++ b/test/cli/testcct @@ -32,6 +32,18 @@ echo "Testing cct -d 8 +proj=merc +R=1" >> ${OUT} echo "90 45" 0 | $EXE -d 8 +proj=merc +R=1 >>${OUT} echo "" >>${OUT} +echo "Test cct with object code initialization" >> ${OUT} +echo "3541657.3778 948984.2343 5201383.5231 2020.5" | $EXE EPSG:8366 >>${OUT} + +echo "Test cct with object name initialization" >> ${OUT} +echo "3541657.3778 948984.2343 5201383.5231 2020.5" | $EXE "ITRF2014 to ETRF2014 (1)" >>${OUT} + +echo "Test cct with object code initialization and file input" >> ${OUT} +echo "3541657.3778 948984.2343 5201383.5231 2020.5" >> a +echo "3541658.0000 948985.0000 5201384.0000 2020.5" >> b +$EXE EPSG:8366 a b >>${OUT} +/bin/rm a b + # do 'diff' with distribution results echo "diff ${OUT} with testcct_out.dist" diff -u ${OUT} ${TEST_CLI_DIR}/testcct_out.dist diff --git a/test/cli/testcct_out.dist b/test/cli/testcct_out.dist index 44dd6964..7788f0bb 100644 --- a/test/cli/testcct_out.dist +++ b/test/cli/testcct_out.dist @@ -1,3 +1,10 @@ Testing cct -d 8 +proj=merc +R=1 1.57079633 0.88137359 0.00000000 inf +Test cct with object code initialization + 3541657.9112 948983.7503 5201383.2482 2020.5000 +Test cct with object name initialization + 3541657.9112 948983.7503 5201383.2482 2020.5000 +Test cct with object code initialization and file input + 3541657.9112 948983.7503 5201383.2482 2020.5000 + 3541658.5334 948984.5160 5201383.7251 2020.5000 |
