From fd0f8849bb8a217e5f7c788f65f47a5b90bc1720 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Sat, 16 Feb 2019 13:20:43 +0100 Subject: Make sure that projinfo man-page is added to source distribution --- man/man1/Makefile.am | 2 +- man/man1/projinfo.1 | 410 ++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/update_man.sh | 1 + 3 files changed, 412 insertions(+), 1 deletion(-) create mode 100644 man/man1/projinfo.1 diff --git a/man/man1/Makefile.am b/man/man1/Makefile.am index b8a59ff2..7aadabb4 100644 --- a/man/man1/Makefile.am +++ b/man/man1/Makefile.am @@ -1,4 +1,4 @@ -man_MANS = geod.1 proj.1 cs2cs.1 cct.1 gie.1 +man_MANS = geod.1 proj.1 cs2cs.1 cct.1 gie.1 projinfo.1 EXTRA_DIST = $(man_MANS) diff --git a/man/man1/projinfo.1 b/man/man1/projinfo.1 new file mode 100644 index 00000000..fcfe3345 --- /dev/null +++ b/man/man1/projinfo.1 @@ -0,0 +1,410 @@ +.\" Man page generated from reStructuredText. +. +.TH "PROJINFO" "1" "Feb 14, 2019" "6.0.0" "PROJ.4" +.SH NAME +projinfo \- Geodetic object and coordinate operation queries +. +.nr rst2man-indent-level 0 +. +.de1 rstReportMargin +\\$1 \\n[an-margin] +level \\n[rst2man-indent-level] +level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] +- +\\n[rst2man-indent0] +\\n[rst2man-indent1] +\\n[rst2man-indent2] +.. +.de1 INDENT +.\" .rstReportMargin pre: +. RS \\$1 +. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] +. nr rst2man-indent-level +1 +.\" .rstReportMargin post: +.. +.de UNINDENT +. RE +.\" indent \\n[an-margin] +.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] +.nr rst2man-indent-level -1 +.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] +.in \\n[rst2man-indent\\n[rst2man-indent-level]]u +.. +.SH SYNOPSIS +.INDENT 0.0 +.INDENT 3.5 +.nf +\fBprojinfo\fP +.in +2 +[\-o formats] [\-k crs|operation] [\-\-summary] [\-q] +[[\-\-area name_or_code] | [\-\-bbox west_long,south_lat,east_long,north_lat]] +[\-\-spatial\-test contains|intersects] +[\-\-crs\-extent\-use none|both|intersection|smallest] +[\-\-grid\-check none|discard_missing|sort] [\-\-show\-superseded] +[\-\-pivot\-crs none|{auth:code[,auth:code]*}] +[\-\-boundcrs\-to\-wgs84] +[\-\-main\-db\-path path] [\-\-aux\-db\-path path]* +[\-\-identify] +[\-\-c\-ify] [\-\-single\-line] +{object_definition} | (\-s {srs_def} \-t {srs_def}) + +.in -2 +.fi +.sp +.sp +where {object_definition} or {object_definition} is a PROJ string, a +WKT string, an object name or a AUTHORITY:CODE +(where AUTHORITY is the name of a CRS authority and CODE the code of a CRS +found in the proj.db database). +.UNINDENT +.UNINDENT +.SH DESCRIPTION +.sp +\fBprojinfo\fP is a program that can query information on a geodetic object, +coordinate reference system (CRS) or coordinate operation, when the \fB\-s\fP and \fB\-t\fP +options are specified, and display it under different formats (PROJ string, WKT string). +.sp +It can also be used to query coordinate operations available between two CRS. +.sp +The program is named with some reference to the GDAL \fBgdalsrsinfo\fP that offers +partly similar services. +.sp +The following control parameters can appear in any order: +.INDENT 0.0 +.TP +.B \-o formats +formats is a comma separated combination of: +\fBall\fP, \fBdefault\fP, \fBPROJ\fP, \fBWKT_ALL\fP, \fBWKT2_2015\fP, \fBWKT2_2018\fP, \fBWKT1_GDAL\fP, \fBWKT1_ESRI\fP\&. +.sp +Except \fBall\fP and \fBdefault\fP, other formats can be preceded by \fB\-\fP to disable them. +.UNINDENT +.INDENT 0.0 +.TP +.B \-k crs|operation +When used to query a single object with a AUTHORITY:CODE, determines the (k)ind of the object +in case there are CRS or coordinate operations with the same CODE. +The default is crs. +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-summary +When listing coordinate operations available between 2 CRS, return the +result in a summary format, mentionning only the name of the coordinate +operation, its accuracy and its area of use. +.sp +\fBNOTE:\fP +.INDENT 7.0 +.INDENT 3.5 +only used for coordinate operation computation +.UNINDENT +.UNINDENT +.UNINDENT +.INDENT 0.0 +.TP +.B \-q +Turn on quiet mode. Quiet mode is only available for queries on single objects, +and only one output format is selected. In that mode, only the PROJ or WKT +string is displayed, without other introduction output. The output is then +potentially compatible of being piped in other utilities. +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-area name_or_code +Specify an area of interest to restrict the results when researching +coordinate operations between 2 CRS. The area of interest can be specified either +as a name (e.g "Denmark \- onshore") or a AUTHORITY:CODE (EPSG:3237) +This option is exclusive of \fI\%\-\-bbox\fP\&. +.sp +\fBNOTE:\fP +.INDENT 7.0 +.INDENT 3.5 +only used for coordinate operation computation +.UNINDENT +.UNINDENT +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-bbox west_long,south_lat,east_long,north_lat +Specify an area of interest to restrict the results when researching +coordinate operations between 2 CRS. The area of interest is specified as a +bounding box with geographic coordinates, expressed in degrees in a +unspecified geographic CRS. +\fIwest_long\fP and \fIeast_long\fP should be in the [\-180,180] range, and +\fIsouth_lat\fP and \fInorth_lat\fP in the [\-90,90]. \fIwest_long\fP is generally lower than +\fIeast_long\fP, except in the case where the area of interest crosses the antimeridian. +.sp +\fBNOTE:\fP +.INDENT 7.0 +.INDENT 3.5 +only used for coordinate operation computation +.UNINDENT +.UNINDENT +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-spatial\-test contains|intersects +Specify how the area of use of coordinate operations found in the database +are compared to the area of use specfied explicitly with \fI\%\-\-area\fP or \fI\%\-\-bbox\fP, +or derivedi implictly from the area of use of the source and target CRS. +By default, projinfo will only keep coordinate operations whose are of use +is strictly within the area of interest (\fBcontains\fP strategy). +If using the \fBintersects\fP strategy, the spatial test is relaxed, and any +coordinate operation whose area of use at least partly intersects the +area of interest is listed. +.sp +\fBNOTE:\fP +.INDENT 7.0 +.INDENT 3.5 +only used for coordinate operation computation +.UNINDENT +.UNINDENT +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-crs\-extent\-use none|both|intersection|smallest +Specify which area of interest to consider when no explicit one is specified +with \fI\%\-\-area\fP or \fI\%\-\-bbox\fP options. +By default (\fBsmallest\fP strategy), the area of +use of the source or target CRS will be looked, and the one that is the +smallest one in terms of area will be used as the area of interest. +If using \fBnone\fP, no area of interest is used. +If using \fBboth\fP, only coordinate operations that relate (contain or intersect +depending of the \fI\%\-\-spatial\-test\fP strategy) to the area of use of both CRS +are selected. +If using \fBintersection\fP, the area of interest is the intersection of the +bounding box of the area of use of the source and target CRS +.sp +\fBNOTE:\fP +.INDENT 7.0 +.INDENT 3.5 +only used for coordinate operation computation +.UNINDENT +.UNINDENT +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-grid\-check none|discard_missing|sort +Specify how the presence or absence of a horizontal or vertical shift grid +required for a coordinate operation affects the results returned when +researching coordinate operations between 2 CRS. +The default strategy is \fBsort\fP: in that case, all candidate +operations are returned, but the actual availability of the grids is used +to determine the sorting order. That is, if a coordinate operation involves +using a grid that is not available in the PROJ resource directories +(determined by the \fBPROJ_LIB\fP environment variable, it will be listed in +the bottom of the results. +The \fBnone\fP strategy completely disables the checks of presence of grids and +this returns the results as if all the grids where available. +The \fBdiscard_missing\fP strategy discards results that involve grids not +present in the PROJ resource directories. +.sp +\fBNOTE:\fP +.INDENT 7.0 +.INDENT 3.5 +only used for coordinate operation computation +.UNINDENT +.UNINDENT +.UNINDENT +.INDENT 0.0 +.TP +.B \-show\-superseded +When enabled, coordinate operations that are superseded by others will be +listed. Note that supersession is not equivalent to deprecation: superseded +operations are still considered valid although they have a better equivalent, +whereas deprecated operations have been determined to be erroneous and are +not considered at all. +.sp +\fBNOTE:\fP +.INDENT 7.0 +.INDENT 3.5 +only used for coordinate operation computation +.UNINDENT +.UNINDENT +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-pivot\-crs none|{auth:code[,auth:code]*} +Determine if intermediate (pivot) CRS can be used when researching coordinate +operation between 2 CRS. A typical example is the WGS84 pivot. By default, +projinfo will consider any potential pivot. If using the \fBnone\fP strategy, +only direct transformations between the source and target CRS will be +used. It is also possible to restrict the pivot CRS to consider by specifying +one or several CRS by their AUTHORITY:CODE. +.sp +\fBNOTE:\fP +.INDENT 7.0 +.INDENT 3.5 +only used for coordinate operation computation +.UNINDENT +.UNINDENT +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-boundcrs\-to\-wgs84 +When specified, this option researches a coordinate operation from the +base geographic CRS of the single CRS, source or target CRS to the WGS84 +geographic CRS, and if found, wraps those CRS into a BoundCRS object. +This is mostly to be used for early\-binding approaches. +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-main\-db\-path path +Specify the name and path of the database to be used by projinfo. The +default is proj.db in the PROJ resource directories. +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-aux\-db\-path path +Specify the name and path of auxiliary databases, that are to be combined +with the main database. Those auxiliary databases must have a table +structure that is identical to the main database, but can be partly filled +and their entries can refer to entries of the main database. +The option may be repeated to specify several auxiliary databases. +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-c\-ify +For developers only. Modify the string output of the utility so that it +is easy to put those strings in C/C++ code +.UNINDENT +.INDENT 0.0 +.TP +.B \-\-single\-line +Output WKT strings on a single line, instead of multiple intended lines by +default. +.UNINDENT +.SH EXAMPLES +.INDENT 0.0 +.IP 1. 3 +Query the CRS object corresponding to EPSG:4326 +.UNINDENT +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +projinfo EPSG:4326 +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +Output: +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +PROJ.4 string: ++proj=longlat +datum=WGS84 +no_defs +type=crs + +WKT2_2018 string: +GEOGCRS["WGS 84", + DATUM["World Geodetic System 1984", + ELLIPSOID["WGS 84",6378137,298.257223563, + LENGTHUNIT["metre",1]]], + PRIMEM["Greenwich",0, + ANGLEUNIT["degree",0.0174532925199433]], + CS[ellipsoidal,2], + AXIS["geodetic latitude (Lat)",north, + ORDER[1], + ANGLEUNIT["degree",0.0174532925199433]], + AXIS["geodetic longitude (Lon)",east, + ORDER[2], + ANGLEUNIT["degree",0.0174532925199433]], + USAGE[ + SCOPE["unknown"], + AREA["World"], + BBOX[\-90,\-180,90,180]], + ID["EPSG",4326]] +.ft P +.fi +.UNINDENT +.UNINDENT +.INDENT 0.0 +.IP 2. 3 +List the coordinate operations between NAD27 (designed with its CRS name) +and NAD83 (designed with its EPSG code 4269) within an area of interest +.UNINDENT +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +projinfo \-s NAD27 \-t EPSG:4269 \-\-area "USA \- Missouri" +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +Output: +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +DERIVED_FROM(EPSG):1241, NAD27 to NAD83 (1), 0.15 m, USA \- CONUS including EEZ + +PROJ string: ++proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert \e ++xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=conus \e ++step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1 + +WKT2_2018 string: +COORDINATEOPERATION["NAD27 to NAD83 (1)", + SOURCECRS[ + GEOGCRS["NAD27", + DATUM["North American Datum 1927", + ELLIPSOID["Clarke 1866",6378206.4,294.978698213898, + LENGTHUNIT["metre",1]]], + PRIMEM["Greenwich",0, + ANGLEUNIT["degree",0.0174532925199433]], + CS[ellipsoidal,2], + AXIS["geodetic latitude (Lat)",north, + ORDER[1], + ANGLEUNIT["degree",0.0174532925199433]], + AXIS["geodetic longitude (Lon)",east, + ORDER[2], + ANGLEUNIT["degree",0.0174532925199433]]]], + TARGETCRS[ + GEOGCRS["NAD83", + DATUM["North American Datum 1983", + ELLIPSOID["GRS 1980",6378137,298.257222101, + LENGTHUNIT["metre",1]]], + PRIMEM["Greenwich",0, + ANGLEUNIT["degree",0.0174532925199433]], + CS[ellipsoidal,2], + AXIS["geodetic latitude (Lat)",north, + ORDER[1], + ANGLEUNIT["degree",0.0174532925199433]], + AXIS["geodetic longitude (Lon)",east, + ORDER[2], + ANGLEUNIT["degree",0.0174532925199433]]]], + METHOD["CTABLE2"], + PARAMETERFILE["Latitude and longitude difference file","conus"], + OPERATIONACCURACY[0.15], + USAGE[ + SCOPE["unknown"], + AREA["USA \- CONUS including EEZ"], + BBOX[23.81,\-129.17,49.38,\-65.69]], + ID["DERIVED_FROM(EPSG)",1241]] +.ft P +.fi +.UNINDENT +.UNINDENT +.SH SEE ALSO +.sp +\fBcs2cs(1)\fP, \fBcct(1)\fP, \fBgeod(1)\fP, \fBgie(1)\fP, \fBproj(1)\fP +.SH BUGS +.sp +A list of know bugs can be found at \fI\%https://github.com/OSGeo/proj.4/issues\fP +where new bug reports can be submitted to. +.SH HOME PAGE +.sp +\fI\%https://proj4.org/\fP +.SH AUTHOR +Even Rouault +.SH COPYRIGHT +1983-2019 +.\" Generated by docutils manpage writer. +. diff --git a/scripts/update_man.sh b/scripts/update_man.sh index fabd08e3..a058f739 100755 --- a/scripts/update_man.sh +++ b/scripts/update_man.sh @@ -8,6 +8,7 @@ git add man/man1/cs2cs.1 git add man/man1/cct.1 git add man/man1/geod.1 git add man/man1/gie.1 +git add man/man1/projinfo.1 git add man/man3/geodesic.3 git add man/man3/pj_init.3 git commit -m "Update man-pages from Sphinx-docs" -- cgit v1.2.3 From 9689243b940e6b908db377dee357f422a00129e8 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 16 Feb 2019 19:19:43 +0100 Subject: Make sure that the PJ object returned by proj_create_crs_to_crs() is a proper CoordinateOperation so that we can call proj_get_source_crs() on it for example --- src/4D_api.cpp | 49 +++++++++----------------------------------- test/unit/gie_self_tests.cpp | 6 ++++++ 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/src/4D_api.cpp b/src/4D_api.cpp index b44cdf39..1b3374f3 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -817,23 +817,6 @@ std::string pj_add_type_crs_if_needed(const std::string& str) return ret; } -/*****************************************************************************/ -static PJ* op_to_pj(PJ_CONTEXT* ctx, PJ* op) -/*****************************************************************************/ -{ - auto proj_string = proj_as_proj_string(ctx, op, PJ_PROJ_5, nullptr); - if( !proj_string) { - return nullptr; - } - - if( proj_string[0] == '\0' ) { - /* Null transform ? */ - return proj_create(ctx, "proj=affine"); - } else { - return proj_create(ctx, proj_string); - } -} - /*****************************************************************************/ static void reproject_bbox(PJ* pjGeogToCrs, double west_lon, double south_lat, @@ -890,7 +873,7 @@ static void reproject_bbox(PJ* pjGeogToCrs, /*****************************************************************************/ -static PJ* add_coord_op_to_list(PJ_CONTEXT* ctx, PJ* op, +static PJ* add_coord_op_to_list(PJ* op, double west_lon, double south_lat, double east_lon, double north_lat, PJ* pjGeogToSrc, @@ -916,15 +899,10 @@ static PJ* add_coord_op_to_list(PJ_CONTEXT* ctx, PJ* op, { const char* c_name = proj_get_name(op); std::string name(c_name ? c_name : ""); - auto pj = op_to_pj(ctx, op); - proj_destroy(op); + altCoordOps.emplace_back(minxSrc, minySrc, maxxSrc, maxySrc, + minxDst, minyDst, maxxDst, maxyDst, + op, name); op = nullptr; - if( pj ) - { - altCoordOps.emplace_back(minxSrc, minySrc, maxxSrc, maxySrc, - minxDst, minyDst, maxxDst, maxyDst, - pj, name); - } } return op; } @@ -988,9 +966,7 @@ static PJ* create_operation_to_base_geog_crs(PJ_CONTEXT* ctx, PJ* crs) { auto opGeogToCrs = proj_list_get(ctx, op_list_to_geodetic, 0); assert(opGeogToCrs); proj_list_destroy(op_list_to_geodetic); - auto P = op_to_pj(ctx, opGeogToCrs); - proj_destroy(opGeogToCrs); - return P; + return opGeogToCrs; } /*****************************************************************************/ @@ -1072,13 +1048,8 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char return nullptr; } - PJ* P; - { - auto op = proj_list_get(ctx, op_list, 0); - assert(op); - P = op_to_pj(ctx, op); - proj_destroy(op); - } + PJ* P = proj_list_get(ctx, op_list, 0); + assert(P); if( P == nullptr || op_count == 1 || (area && area->bbox_set) || proj_get_type(src) == PJ_TYPE_GEOCENTRIC_CRS || @@ -1141,7 +1112,7 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char { if( west_lon <= east_lon ) { - op = add_coord_op_to_list(ctx, op, + op = add_coord_op_to_list(op, west_lon, south_lat, east_lon, north_lat, pjGeogToSrc, pjGeogToDst, P->alternativeCoordinateOperations); @@ -1150,11 +1121,11 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char { auto op_clone = proj_clone(ctx, op); - op = add_coord_op_to_list(ctx, op, + op = add_coord_op_to_list(op, west_lon, south_lat, 180, north_lat, pjGeogToSrc, pjGeogToDst, P->alternativeCoordinateOperations); - op_clone = add_coord_op_to_list(ctx, op_clone, + op_clone = add_coord_op_to_list(op_clone, -180, south_lat, east_lon, north_lat, pjGeogToSrc, pjGeogToDst, P->alternativeCoordinateOperations); diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 7f9f436b..91a3069c 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -258,6 +258,12 @@ TEST_F(gieTest, proj_create_crs_to_crs) { a = proj_trans(P, PJ_FWD, a); EXPECT_NEAR(a.xy.x, b.xy.x, 1e-9); EXPECT_NEAR(a.xy.y, b.xy.y, 1e-9); + + auto src = proj_get_source_crs(PJ_DEFAULT_CTX, P); + ASSERT_TRUE(src != nullptr); + EXPECT_EQ(proj_get_name(src), std::string("ETRS89 / UTM zone 32N")); + proj_destroy(src); + proj_destroy(P); /* we can also allow PROJ strings as a usable PJ */ -- cgit v1.2.3 From 4c61b3c882c8c47d40c3950f95c640710804835f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 16 Feb 2019 23:06:34 +0100 Subject: Make sure proj_get_source_crs() and proj_get_target_crs() work on 'pseudo' PJ object returned by proj_create_crs_to_crs() when there are several alternatives --- src/iso19111/c_api.cpp | 8 ++++++++ test/unit/gie_self_tests.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index 240d11b3..79732bab 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -1736,6 +1736,10 @@ PJ *proj_get_source_crs(PJ_CONTEXT *ctx, const PJ *obj) { } return nullptr; } + if (!obj->alternativeCoordinateOperations.empty()) { + return proj_get_source_crs(ctx, + obj->alternativeCoordinateOperations[0].pj); + } proj_log_error(ctx, __FUNCTION__, "Object is not a BoundCRS or a CoordinateOperation"); return nullptr; @@ -1771,6 +1775,10 @@ PJ *proj_get_target_crs(PJ_CONTEXT *ctx, const PJ *obj) { } return nullptr; } + if (!obj->alternativeCoordinateOperations.empty()) { + return proj_get_target_crs(ctx, + obj->alternativeCoordinateOperations[0].pj); + } proj_log_error(ctx, __FUNCTION__, "Object is not a BoundCRS or a CoordinateOperation"); return nullptr; diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 91a3069c..5936791e 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -680,6 +680,18 @@ TEST(gie, proj_create_crs_to_crs_PULKOVO42_ETRS89) { EXPECT_EQ(P->fwd3d, nullptr); EXPECT_EQ(P->fwd4d, nullptr); + // get source CRS even if the P object is in a dummy state + auto src_crs = proj_get_source_crs(PJ_DEFAULT_CTX, P); + EXPECT_TRUE(src_crs != nullptr); + EXPECT_EQ(proj_get_name(src_crs), std::string("Pulkovo 1942(58)")); + proj_destroy(src_crs); + + // get target CRS even if the P object is in a dummy state + auto target_crs = proj_get_target_crs(PJ_DEFAULT_CTX, P); + EXPECT_TRUE(target_crs != nullptr); + EXPECT_EQ(proj_get_name(target_crs), std::string("ETRS89")); + proj_destroy(target_crs); + // Romania c.xyz.x = 45; // Lat c.xyz.y = 25; // Long -- cgit v1.2.3 From a8cbe0c66974871f5a7bd7ef94001ebf461ac7ea Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Sun, 17 Feb 2019 08:42:48 +0100 Subject: Slack tolerance in deg->rad unitconvert test --- test/gie/unitconvert.gie | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gie/unitconvert.gie b/test/gie/unitconvert.gie index 2a56ba59..2e06fe72 100644 --- a/test/gie/unitconvert.gie +++ b/test/gie/unitconvert.gie @@ -26,7 +26,7 @@ accept 1 1 1 1 expect 0.5 0.5 1 1 operation proj=unitconvert xy_in=deg xy_out=rad -tolerance 0.000000000001 +tolerance 0.0000001 accept 1 1 1 1 expect 1 1 1 1 # gie does a rad->deg conversion behind the scenes -- cgit v1.2.3 From e8b2e2a36324006146406fb1fc89ce6ed863807f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 17 Feb 2019 19:40:38 +0100 Subject: Modify the default strategy of researching intermediate CRS to do it only if there is no direct transformation --- docs/source/apps/projinfo.rst | 11 +++--- include/proj/coordinateoperation.hpp | 17 ++++++++-- include/proj/crs.hpp | 7 ++-- src/apps/projinfo.cpp | 50 ++++++++++++++++----------- src/iso19111/c_api.cpp | 44 ++++++++++++++++++------ src/iso19111/coordinateoperation.cpp | 36 +++++++++++--------- src/iso19111/crs.cpp | 9 ++--- src/proj.h | 15 +++++++- test/unit/test_c_api.cpp | 4 ++- test/unit/test_crs.cpp | 66 ++++++++++++++++++++++++------------ test/unit/test_factory.cpp | 3 +- test/unit/test_operation.cpp | 14 ++++++-- 12 files changed, 191 insertions(+), 85 deletions(-) diff --git a/docs/source/apps/projinfo.rst b/docs/source/apps/projinfo.rst index cbfd44d4..af9ed171 100644 --- a/docs/source/apps/projinfo.rst +++ b/docs/source/apps/projinfo.rst @@ -21,7 +21,7 @@ Synopsis | [--spatial-test contains|intersects] | [--crs-extent-use none|both|intersection|smallest] | [--grid-check none|discard_missing|sort] [--show-superseded] - | [--pivot-crs none|{auth:code[,auth:code]*}] + | [--pivot-crs always|if_no_direct_transformation|never|{auth:code[,auth:code]*}] | [--boundcrs-to-wgs84] | [--main-db-path path] [--aux-db-path path]* | [--identify] @@ -157,13 +157,16 @@ The following control parameters can appear in any order: .. note:: only used for coordinate operation computation -.. option:: --pivot-crs none|{auth:code[,auth:code]*} +.. option:: --pivot-crs always|if_no_direct_transformation|never|{auth:code[,auth:code]*} Determine if intermediate (pivot) CRS can be used when researching coordinate operation between 2 CRS. A typical example is the WGS84 pivot. By default, - projinfo will consider any potential pivot. If using the ``none`` strategy, + projinfo will consider any potential pivot if there is no direct transformation + ( ``if_no_direct_transformation``). If using the ``never`` strategy, only direct transformations between the source and target CRS will be - used. It is also possible to restrict the pivot CRS to consider by specifying + used. If using the ``always`` strategy, intermediate CRS will be considered + even if there are direct transformations. + It is also possible to restrict the pivot CRS to consider by specifying one or several CRS by their AUTHORITY:CODE. .. note:: only used for coordinate operation computation diff --git a/include/proj/coordinateoperation.hpp b/include/proj/coordinateoperation.hpp index 6b32e24d..92b655f9 100644 --- a/include/proj/coordinateoperation.hpp +++ b/include/proj/coordinateoperation.hpp @@ -1726,9 +1726,22 @@ class PROJ_GCC_DLL CoordinateOperationContext { PROJ_DLL GridAvailabilityUse getGridAvailabilityUse() const; - PROJ_DLL void setAllowUseIntermediateCRS(bool use); + /** Describe if and how intermediate CRS should be used */ + enum class IntermediateCRSUse { + /** Always search for intermediate CRS. */ + ALWAYS, - PROJ_DLL bool getAllowUseIntermediateCRS() const; + /** Only attempt looking for intermediate CRS if there is no direct + * transformation available. */ + IF_NO_DIRECT_TRANSFORMATION, + + /* Do not attempt looking for intermediate CRS. */ + NEVER, + }; + + PROJ_DLL void setAllowUseIntermediateCRS(IntermediateCRSUse use); + + PROJ_DLL IntermediateCRSUse getAllowUseIntermediateCRS() const; PROJ_DLL void setIntermediateCRS(const std::vector> diff --git a/include/proj/crs.hpp b/include/proj/crs.hpp index 6a09ea78..fb34d3b7 100644 --- a/include/proj/crs.hpp +++ b/include/proj/crs.hpp @@ -92,9 +92,10 @@ class PROJ_GCC_DLL CRS : public common::ObjectUsage { PROJ_DLL GeodeticCRSPtr extractGeodeticCRS() const; PROJ_DLL GeographicCRSPtr extractGeographicCRS() const; PROJ_DLL VerticalCRSPtr extractVerticalCRS() const; - PROJ_DLL CRSNNPtr - createBoundCRSToWGS84IfPossible(const io::DatabaseContextPtr &dbContext, - bool allowIntermediateCRS) const; + PROJ_DLL CRSNNPtr createBoundCRSToWGS84IfPossible( + const io::DatabaseContextPtr &dbContext, + operation::CoordinateOperationContext::IntermediateCRSUse + allowIntermediateCRSUse) const; PROJ_DLL CRSNNPtr stripVerticalComponent() const; PROJ_DLL const BoundCRSPtr &canonicalBoundCRS() PROJ_PURE_DECL; diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 29cf5fc3..9f908c8a 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -88,8 +88,8 @@ static void usage() { << " [--grid-check none|discard_missing|sort] " "[--show-superseded]" << std::endl - << " [--pivot-crs none|{auth:code[,auth:code]*}]" - << std::endl + << " [--pivot-crs always|if_no_direct_transformation|" + << "never|{auth:code[,auth:code]*}]" << std::endl << " [--boundcrs-to-wgs84]" << std::endl << " [--main-db-path path] [--aux-db-path path]*" << std::endl @@ -139,7 +139,7 @@ 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 allowPivots, + bool buildBoundCRSToWGS84, CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS, bool quiet) { BaseObjectPtr obj; @@ -213,7 +213,7 @@ static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext, if (buildBoundCRSToWGS84) { auto crs = std::dynamic_pointer_cast(obj); if (crs) { - obj = crs->createBoundCRSToWGS84IfPossible(dbContext, allowPivots) + obj = crs->createBoundCRSToWGS84IfPossible(dbContext, allowUseIntermediateCRS) .as_nullable(); } } @@ -224,7 +224,7 @@ static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext, // --------------------------------------------------------------------------- static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, - bool allowPivots, const OutputOptions &outputOpt) { + CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS, const OutputOptions &outputOpt) { auto identified = dynamic_cast(obj.get()); if (!outputOpt.quiet && identified && identified->isDeprecated()) { @@ -272,7 +272,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, objToExport = nn_dynamic_pointer_cast( crs->createBoundCRSToWGS84IfPossible(dbContext, - allowPivots)); + allowUseIntermediateCRS)); } if (!objToExport) { objToExport = projStringExportable; @@ -412,7 +412,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (crs) { objToExport = nn_dynamic_pointer_cast( crs->createBoundCRSToWGS84IfPossible(dbContext, - allowPivots)); + allowUseIntermediateCRS)); } if (!objToExport) { objToExport = wktExportable; @@ -516,12 +516,14 @@ static void outputOperations( CoordinateOperationContext::SpatialCriterion spatialCriterion, CoordinateOperationContext::SourceTargetCRSExtentUse crsExtentUse, CoordinateOperationContext::GridAvailabilityUse gridAvailabilityUse, - bool allowPivots, + CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS, const std::vector> &pivots, const std::string &authority, bool usePROJGridAlternatives, bool showSuperseded, const OutputOptions &outputOpt, bool summary) { auto sourceObj = buildObject(dbContext, sourceCRSStr, true, "source CRS", - false, false, outputOpt.quiet); + false, + CoordinateOperationContext::IntermediateCRSUse::NEVER, + outputOpt.quiet); auto sourceCRS = nn_dynamic_pointer_cast(sourceObj); if (!sourceCRS) { std::cerr << "source CRS string is not a CRS" << std::endl; @@ -529,7 +531,9 @@ static void outputOperations( } auto targetObj = buildObject(dbContext, targetCRSStr, true, "target CRS", - false, false, outputOpt.quiet); + false, + CoordinateOperationContext::IntermediateCRSUse::NEVER, + outputOpt.quiet); auto targetCRS = nn_dynamic_pointer_cast(targetObj); if (!targetCRS) { std::cerr << "target CRS string is not a CRS" << std::endl; @@ -548,7 +552,7 @@ static void outputOperations( ctxt->setSpatialCriterion(spatialCriterion); ctxt->setSourceAndTargetCRSExtentUse(crsExtentUse); ctxt->setGridAvailabilityUse(gridAvailabilityUse); - ctxt->setAllowUseIntermediateCRS(allowPivots); + ctxt->setAllowUseIntermediateCRS(allowUseIntermediateCRS); ctxt->setIntermediateCRS(pivots); ctxt->setUsePROJAlternativeGridNames(usePROJGridAlternatives); ctxt->setDiscardSuperseded(!showSuperseded); @@ -560,7 +564,7 @@ static void outputOperations( std::exit(1); } if (outputOpt.quiet && !list.empty()) { - outputObject(dbContext, list[0], allowPivots, outputOpt); + outputObject(dbContext, list[0], allowUseIntermediateCRS, outputOpt); return; } if (summary) { @@ -586,7 +590,7 @@ static void outputOperations( } outputOperationSummary(op); std::cout << std::endl; - outputObject(dbContext, op, allowPivots, outputOpt); + outputObject(dbContext, op, allowUseIntermediateCRS, outputOpt); } } } @@ -617,7 +621,8 @@ int main(int argc, char **argv) { bool buildBoundCRSToWGS84 = false; CoordinateOperationContext::GridAvailabilityUse gridAvailabilityUse = CoordinateOperationContext::GridAvailabilityUse::USE_FOR_SORTING; - bool allowPivots = true; + CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS = + CoordinateOperationContext::IntermediateCRSUse::IF_NO_DIRECT_TRANSFORMATION; std::vector> pivots; bool usePROJGridAlternatives = true; std::string mainDBPath; @@ -814,8 +819,15 @@ int main(int argc, char **argv) { } else if (arg == "--pivot-crs" && i + 1 < argc) { i++; auto value(argv[i]); - if (ci_equal(std::string(value), "none")) { - allowPivots = false; + if (ci_equal(std::string(value), "always")) { + allowUseIntermediateCRS = + CoordinateOperationContext::IntermediateCRSUse::ALWAYS; + } else if (ci_equal(std::string(value), "if_no_direct_transformation")) { + allowUseIntermediateCRS = + CoordinateOperationContext::IntermediateCRSUse::IF_NO_DIRECT_TRANSFORMATION; + } else if (ci_equal(std::string(value), "never")) { + allowUseIntermediateCRS = + CoordinateOperationContext::IntermediateCRSUse::NEVER; } else { auto splitValue(split(value, ',')); for (const auto &v : splitValue) { @@ -915,7 +927,7 @@ int main(int argc, char **argv) { if (!user_string.empty()) { auto obj(buildObject(dbContext, user_string, kindIsCRS, "input string", - buildBoundCRSToWGS84, allowPivots, + buildBoundCRSToWGS84, allowUseIntermediateCRS, outputOpt.quiet)); if (guessDialect) { auto dialect = WKTParser().guessDialect(user_string); @@ -933,7 +945,7 @@ int main(int argc, char **argv) { } std::cout << std::endl; } - outputObject(dbContext, obj, allowPivots, outputOpt); + outputObject(dbContext, obj, allowUseIntermediateCRS, outputOpt); if (identify) { auto crs = dynamic_cast(obj.get()); if (crs) { @@ -1043,7 +1055,7 @@ int main(int argc, char **argv) { outputOperations( dbContext, sourceCRSStr, targetCRSStr, bboxFilter, spatialCriterion, - crsExtentUse, gridAvailabilityUse, allowPivots, pivots, authority, + crsExtentUse, gridAvailabilityUse, allowUseIntermediateCRS, pivots, authority, usePROJGridAlternatives, showSuperseded, outputOpt, summary); } diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index 79732bab..b3f200fe 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -1475,7 +1475,8 @@ PJ *proj_crs_create_bound_crs(PJ_CONTEXT *ctx, const PJ *base_crs, * @param options null-terminated list of options, or NULL. Currently * supported options are: *
    - *
  • ALLOW_INTERMEDIATE_CRS=YES/NO. Defaults to NO. When set to YES, + *
  • ALLOW_INTERMEDIATE_CRS=ALWAYS/IF_NO_DIRECT_TRANSFORMATION/NEVER. Defaults + * to NEVER. When set to ALWAYS/IF_NO_DIRECT_TRANSFORMATION, * intermediate CRS may be considered when computing the possible * transformations. Slower.
  • *
@@ -1493,11 +1494,18 @@ PJ *proj_crs_create_bound_crs_to_WGS84(PJ_CONTEXT *ctx, const PJ *crs, } auto dbContext = getDBcontextNoException(ctx, __FUNCTION__); try { - bool allowIntermediateCRS = false; + CoordinateOperationContext::IntermediateCRSUse allowIntermediateCRS = + CoordinateOperationContext::IntermediateCRSUse::NEVER; for (auto iter = options; iter && iter[0]; ++iter) { const char *value; if ((value = getOptionValue(*iter, "ALLOW_INTERMEDIATE_CRS="))) { - allowIntermediateCRS = ci_equal(value, "YES"); + if (ci_equal(value, "YES") || ci_equal(value, "ALWAYS")) { + allowIntermediateCRS = + CoordinateOperationContext::IntermediateCRSUse::ALWAYS; + } else if (ci_equal(value, "IF_NO_DIRECT_TRANSFORMATION")) { + allowIntermediateCRS = CoordinateOperationContext:: + IntermediateCRSUse::IF_NO_DIRECT_TRANSFORMATION; + } } else { std::string msg("Unknown option :"); msg += *iter; @@ -6378,22 +6386,36 @@ void proj_operation_factory_context_set_use_proj_alternative_grid_names( * The current implementation is limited to researching one intermediate * step. * - * By default, all potential C candidates will be used. - * proj_operation_factory_context_set_allowed_intermediate_crs() - * can be used to restrict them. - * - * The default is true. + * By default, with the IF_NO_DIRECT_TRANSFORMATION stratgey, all potential + * C candidates will be used if there is no direct tranformation. * * @param ctx PROJ context, or NULL for default context * @param factory_ctx Operation factory context. must not be NULL - * @param allow whether intermediate CRS may be used. + * @param use whether and how intermediate CRS may be used. */ void proj_operation_factory_context_set_allow_use_intermediate_crs( - PJ_CONTEXT *ctx, PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, int allow) { + PJ_CONTEXT *ctx, PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, + PROJ_INTERMEDIATE_CRS_USE use) { SANITIZE_CTX(ctx); assert(factory_ctx); try { - factory_ctx->operationContext->setAllowUseIntermediateCRS(allow != 0); + switch (use) { + case PROJ_INTERMEDIATE_CRS_USE_ALWAYS: + factory_ctx->operationContext->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::ALWAYS); + break; + + case PROJ_INTERMEDIATE_CRS_USE_IF_NO_DIRECT_TRANSFORMATION: + factory_ctx->operationContext->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse:: + IF_NO_DIRECT_TRANSFORMATION); + break; + + case PROJ_INTERMEDIATE_CRS_USE_NEVER: + factory_ctx->operationContext->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::NEVER); + break; + } } catch (const std::exception &e) { proj_log_error(ctx, __FUNCTION__, e.what()); } diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp index d964cdc1..2128124b 100644 --- a/src/iso19111/coordinateoperation.cpp +++ b/src/iso19111/coordinateoperation.cpp @@ -9242,7 +9242,8 @@ struct CoordinateOperationContext::Private { bool usePROJNames_ = true; GridAvailabilityUse gridAvailabilityUse_ = GridAvailabilityUse::USE_FOR_SORTING; - bool allowUseIntermediateCRS_ = true; + IntermediateCRSUse allowUseIntermediateCRS_ = CoordinateOperationContext:: + IntermediateCRSUse::IF_NO_DIRECT_TRANSFORMATION; std::vector> intermediateCRSAuthCodes_{}; bool discardSuperseded_ = true; @@ -9436,18 +9437,17 @@ CoordinateOperationContext::getGridAvailabilityUse() const { * * Concretely if in the database there is an operation from A to C * (or C to A), and another one from C to B (or B to C), but no direct - * operation between A and B, setting this parameter to true, allow - * chaining both operations. + * operation between A and B, setting this parameter to + * ALWAYS/IF_NO_DIRECT_TRANSFORMATION, allow chaining both operations. * * The current implementation is limited to researching one intermediate * step. * - * By default, all potential C candidates will be used. setIntermediateCRS() - * can be used to restrict them. - * - * The default is true. + * By default, with the IF_NO_DIRECT_TRANSFORMATION stratgey, all potential + * C candidates will be used if there is no direct tranformation. */ -void CoordinateOperationContext::setAllowUseIntermediateCRS(bool use) { +void CoordinateOperationContext::setAllowUseIntermediateCRS( + IntermediateCRSUse use) { d->allowUseIntermediateCRS_ = use; } @@ -9458,12 +9458,13 @@ void CoordinateOperationContext::setAllowUseIntermediateCRS(bool use) { * * Concretely if in the database there is an operation from A to C * (or C to A), and another one from C to B (or B to C), but no direct - * operation between A and B, setting this parameter to true, allow - * chaining both operations. + * operation between A and B, setting this parameter to + * ALWAYS/IF_NO_DIRECT_TRANSFORMATION, allow chaining both operations. * - * The default is true. + * The default is IF_NO_DIRECT_TRANSFORMATION. */ -bool CoordinateOperationContext::getAllowUseIntermediateCRS() const { +CoordinateOperationContext::IntermediateCRSUse +CoordinateOperationContext::getAllowUseIntermediateCRS() const { return d->allowUseIntermediateCRS_; } @@ -10401,9 +10402,6 @@ findOpsInRegistryDirect(const crs::CRSNNPtr &sourceCRS, static std::vector findsOpsInRegistryWithIntermediate( const crs::CRSNNPtr &sourceCRS, const crs::CRSNNPtr &targetCRS, const CoordinateOperationContextNNPtr &context) { - if (!context->getAllowUseIntermediateCRS()) { - return std::vector(); - } const auto &authFactory = context->getAuthorityFactory(); assert(authFactory); @@ -11215,7 +11213,13 @@ CoordinateOperationFactory::Private::createOperations( // NAD27 to NAD83 has tens of results already. No need to look // for a pivot - if (res.size() < 5 || getenv("PROJ_FORCE_SEARCH_PIVOT")) { + if ((res.empty() && + context.context->getAllowUseIntermediateCRS() == + CoordinateOperationContext::IntermediateCRSUse:: + IF_NO_DIRECT_TRANSFORMATION) || + context.context->getAllowUseIntermediateCRS() == + CoordinateOperationContext::IntermediateCRSUse::ALWAYS || + getenv("PROJ_FORCE_SEARCH_PIVOT")) { auto resWithIntermediate = findsOpsInRegistryWithIntermediate( sourceCRS, targetCRS, context.context); res.insert(res.end(), resWithIntermediate.begin(), diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index ebbed7a1..01a588e3 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -375,9 +375,10 @@ VerticalCRSPtr CRS::extractVerticalCRS() const { * * @return a CRS. */ -CRSNNPtr -CRS::createBoundCRSToWGS84IfPossible(const io::DatabaseContextPtr &dbContext, - bool allowIntermediateCRS) const { +CRSNNPtr CRS::createBoundCRSToWGS84IfPossible( + const io::DatabaseContextPtr &dbContext, + operation::CoordinateOperationContext::IntermediateCRSUse + allowIntermediateCRSUse) const { auto thisAsCRS = NN_NO_CHECK( std::static_pointer_cast(shared_from_this().as_nullable())); auto boundCRS = util::nn_dynamic_pointer_cast(thisAsCRS); @@ -442,7 +443,7 @@ CRS::createBoundCRSToWGS84IfPossible(const io::DatabaseContextPtr &dbContext, authority == "any" ? std::string() : authority); auto ctxt = operation::CoordinateOperationContext::create( authFactory, extent, 0.0); - ctxt->setAllowUseIntermediateCRS(allowIntermediateCRS); + ctxt->setAllowUseIntermediateCRS(allowIntermediateCRSUse); // ctxt->setSpatialCriterion( // operation::CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION); auto list = diff --git a/src/proj.h b/src/proj.h index f25c3228..af22c341 100644 --- a/src/proj.h +++ b/src/proj.h @@ -629,6 +629,19 @@ typedef enum { PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION } PROJ_SPATIAL_CRITERION; + /** Describe if and how intermediate CRS should be used */ +typedef enum { + /** Always search for intermediate CRS. */ + PROJ_INTERMEDIATE_CRS_USE_ALWAYS, + + /** Only attempt looking for intermediate CRS if there is no direct + * transformation available. */ + PROJ_INTERMEDIATE_CRS_USE_IF_NO_DIRECT_TRANSFORMATION, + + /* Do not attempt looking for intermediate CRS. */ + PROJ_INTERMEDIATE_CRS_USE_NEVER, +} PROJ_INTERMEDIATE_CRS_USE; + /** Type of coordinate system. */ typedef enum { @@ -906,7 +919,7 @@ void PROJ_DLL proj_operation_factory_context_set_use_proj_alternative_grid_names void PROJ_DLL proj_operation_factory_context_set_allow_use_intermediate_crs( PJ_CONTEXT *ctx, PJ_OPERATION_FACTORY_CONTEXT *factory_ctx, - int allow); + PROJ_INTERMEDIATE_CRS_USE use); void PROJ_DLL proj_operation_factory_context_set_allowed_intermediate_crs( PJ_CONTEXT *ctx, diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index 273a04e6..6205a9b8 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -1389,7 +1389,7 @@ TEST_F(CApi, proj_create_operations_with_pivot) { ASSERT_NE(ctxt, nullptr); ContextKeeper keeper_ctxt(ctxt); proj_operation_factory_context_set_allow_use_intermediate_crs( - m_ctxt, ctxt, false); + m_ctxt, ctxt, PROJ_INTERMEDIATE_CRS_USE_NEVER); auto res = proj_create_operations(m_ctxt, source_crs, target_crs, ctxt); ASSERT_NE(res, nullptr); @@ -1444,6 +1444,8 @@ TEST_F(CApi, proj_create_operations_with_pivot) { m_ctxt, ctxt, PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION); proj_operation_factory_context_set_grid_availability_use( m_ctxt, ctxt, PROJ_GRID_AVAILABILITY_IGNORED); + proj_operation_factory_context_set_allow_use_intermediate_crs( + m_ctxt, ctxt, PROJ_INTERMEDIATE_CRS_USE_ALWAYS); auto res = proj_create_operations(m_ctxt, source_crs, target_crs, ctxt); ASSERT_NE(res, nullptr); diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index 26bcf621..4953529c 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -3436,8 +3436,12 @@ TEST(crs, boundCRS_crs_link) { EXPECT_TRUE(baseCRS->isEquivalentTo(GeographicCRS::EPSG_4267.get())); EXPECT_TRUE(baseCRS->canonicalBoundCRS() != nullptr); - EXPECT_TRUE(baseCRS->createBoundCRSToWGS84IfPossible(nullptr, false) - ->isEquivalentTo(baseCRS->canonicalBoundCRS().get())); + EXPECT_TRUE( + baseCRS + ->createBoundCRSToWGS84IfPossible( + nullptr, + CoordinateOperationContext::IntermediateCRSUse::NEVER) + ->isEquivalentTo(baseCRS->canonicalBoundCRS().get())); } { @@ -4725,27 +4729,35 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { auto factory = AuthorityFactory::create(dbContext, "EPSG"); { auto crs_4326 = factory->createCoordinateReferenceSystem("4326"); - EXPECT_EQ(crs_4326->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(crs_4326->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), crs_4326); } { auto crs_32631 = factory->createCoordinateReferenceSystem("32631"); - EXPECT_EQ(crs_32631->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(crs_32631->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), crs_32631); } { // Pulkovo 42 East Germany auto crs_5670 = factory->createCoordinateReferenceSystem("5670"); - EXPECT_EQ(crs_5670->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(crs_5670->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), crs_5670); } { // Pulkovo 42 Romania auto crs_3844 = factory->createCoordinateReferenceSystem("3844"); - auto bound = - crs_3844->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs_3844->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs_3844); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), bound); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4759,10 +4771,12 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { { // Pulkovo 42 Poland auto crs_2171 = factory->createCoordinateReferenceSystem("2171"); - auto bound = - crs_2171->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs_2171->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs_2171); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), bound); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4776,10 +4790,12 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { { // NTF (Paris) auto crs_4807 = factory->createCoordinateReferenceSystem("4807"); - auto bound = - crs_4807->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs_4807->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs_4807); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), bound); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4791,10 +4807,12 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { { // NTF (Paris) / Lambert zone II + NGF-IGN69 height auto crs_7421 = factory->createCoordinateReferenceSystem("7421"); - auto bound = - crs_7421->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs_7421->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs_7421); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), bound); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4807,13 +4825,17 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { } { auto crs = createVerticalCRS(); - EXPECT_EQ(crs->createBoundCRSToWGS84IfPossible(dbContext, false), crs); + EXPECT_EQ(crs->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), + crs); } { auto factoryIGNF = AuthorityFactory::create(DatabaseContext::create(), "IGNF"); auto crs = factoryIGNF->createCoordinateReferenceSystem("TERA50STEREO"); - auto bound = crs->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4827,7 +4849,8 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { auto factoryIGNF = AuthorityFactory::create(DatabaseContext::create(), "IGNF"); auto crs = factoryIGNF->createCoordinateReferenceSystem("PGP50"); - auto bound = crs->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4838,7 +4861,8 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { } { auto crs = factory->createCoordinateReferenceSystem("4269"); // NAD83 - auto bound = crs->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_EQ(bound, crs); } } diff --git a/test/unit/test_factory.cpp b/test/unit/test_factory.cpp index 40728f96..ec59dcbc 100644 --- a/test/unit/test_factory.cpp +++ b/test/unit/test_factory.cpp @@ -1612,7 +1612,8 @@ class FactoryWithTmpDatabase : public ::testing::Test { { auto ctxt = CoordinateOperationContext::create(factory, nullptr, 0); - ctxt->setAllowUseIntermediateCRS(false); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::NEVER); res = CoordinateOperationFactory::create()->createOperations( srcCRS, targetCRS, ctxt); EXPECT_EQ(res.size(), 1U); diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp index 103b856c..c7f9cb7d 100644 --- a/test/unit/test_operation.cpp +++ b/test/unit/test_operation.cpp @@ -4181,7 +4181,8 @@ TEST(operation, geogCRS_to_geogCRS_context_default) { auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0); ctxt->setSpatialCriterion( CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION); - ctxt->setAllowUseIntermediateCRS(false); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::NEVER); // Directly found in database { @@ -4237,7 +4238,8 @@ TEST(operation, geogCRS_to_geogCRS_context_match_by_name) { auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0); ctxt->setSpatialCriterion( CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION); - ctxt->setAllowUseIntermediateCRS(false); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::NEVER); auto NAD27 = GeographicCRS::create( PropertyMap().set(IdentifiedObject::NAME_KEY, GeographicCRS::EPSG_4267->nameStr()), @@ -4577,6 +4579,8 @@ TEST(operation, geogCRS_to_geogCRS_context_concatenated_operation) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::ALWAYS); auto list = CoordinateOperationFactory::create()->createOperations( authFactory->createCoordinateReferenceSystem("4807"), // NTF(Paris) authFactory->createCoordinateReferenceSystem("4171"), // RGF93 @@ -4640,6 +4644,8 @@ TEST(operation, geogCRS_to_geogCRS_CH1903_to_CH1903plus_context) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::ALWAYS); auto list = CoordinateOperationFactory::create()->createOperations( authFactory->createCoordinateReferenceSystem("4149"), // CH1903 authFactory->createCoordinateReferenceSystem("4150"), // CH1903+ @@ -5113,6 +5119,8 @@ TEST(operation, auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::ALWAYS); auto list = CoordinateOperationFactory::create()->createOperations( authFactory->createCoordinateReferenceSystem("4807"), // NTF(Paris) authFactory->createCoordinateReferenceSystem("32631"), // UTM31 WGS84 @@ -6191,6 +6199,8 @@ TEST(operation, IGNF_LAMB1_TO_EPSG_4326) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), std::string()); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::ALWAYS); auto list = CoordinateOperationFactory::create()->createOperations( AuthorityFactory::create(DatabaseContext::create(), "IGNF") ->createCoordinateReferenceSystem("LAMB1"), -- cgit v1.2.3 From 1b272fc9ee5d25a0cb07d6d12df13c6a77eeb7f0 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 17 Feb 2019 20:52:46 +0100 Subject: tests: implement fuzzy proj string comparison in a few problematic test cases on non-x86 arch (fixes #1275) --- test/unit/Makefile.am | 2 +- test/unit/test_factory.cpp | 12 +++-- test/unit/test_operation.cpp | 100 ++++++++++++++++++++++++------------------ test/unit/test_primitives.hpp | 99 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+), 48 deletions(-) create mode 100644 test/unit/test_primitives.hpp diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 210bdc90..57a03ca8 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = subdir-objects EXTRA_DIST = CMakeLists.txt -noinst_HEADERS = gtest_include.h +noinst_HEADERS = gtest_include.h test_primitives.hpp AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include -I$(top_srcdir)/test @GTEST_CFLAGS@ @SQLITE3_CFLAGS@ AM_CXXFLAGS = @CXX_WFLAGS@ @NO_ZERO_AS_NULL_POINTER_CONSTANT_FLAG@ diff --git a/test/unit/test_factory.cpp b/test/unit/test_factory.cpp index 40728f96..d5c82afb 100644 --- a/test/unit/test_factory.cpp +++ b/test/unit/test_factory.cpp @@ -28,6 +28,8 @@ #include "gtest_include.h" +#include "test_primitives.hpp" + #include "proj/common.hpp" #include "proj/coordinateoperation.hpp" #include "proj/coordinatesystem.hpp" @@ -991,10 +993,12 @@ TEST(factory, AuthorityFactory_test_uom_9110) { auto factory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); // This tests conversion from unit of measure EPSG:9110 DDD.MMSSsss auto crs = factory->createProjectedCRS("2172"); - EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=sterea +lat_0=53.0019444444444 +lon_0=21.5027777777778 " - "+k=0.9998 +x_0=4603000 +y_0=5806000 +ellps=krass +units=m " - "+no_defs +type=crs"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + crs->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=sterea +lat_0=53.0019444444444 +lon_0=21.5027777777778 " + "+k=0.9998 +x_0=4603000 +y_0=5806000 +ellps=krass +units=m " + "+no_defs +type=crs"); } // --------------------------------------------------------------------------- diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp index 103b856c..344f79b7 100644 --- a/test/unit/test_operation.cpp +++ b/test/unit/test_operation.cpp @@ -28,8 +28,12 @@ #include "gtest_include.h" +#include "test_primitives.hpp" + // to be able to use internal::replaceAll +#ifndef FROM_PROJ_CPP #define FROM_PROJ_CPP +#endif #include "proj/common.hpp" #include "proj/coordinateoperation.hpp" @@ -4861,11 +4865,13 @@ TEST(operation, geocentricCRS_to_geocentricCRS_different_datum_context) { authFactory->createCoordinateReferenceSystem("4896"), ctxt); ASSERT_EQ(list.size(), 1U); EXPECT_EQ(list[0]->nameStr(), "ITRF2000 to ITRF2005 (1)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector"); } // --------------------------------------------------------------------------- @@ -4904,15 +4910,17 @@ TEST(operation, "Conversion from ITRF2000 (geog3D) to ITRF2000 (geocentric) + " "ITRF2000 to ITRF2005 (1) + " "Conversion from ITRF2005 (geocentric) to ITRF2005 (geog3D)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=pipeline +step +proj=axisswap +order=2,1 +step " - "+proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m " - "+step +proj=cart +ellps=GRS80 +step +proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector +step +inv " - "+proj=cart +ellps=GRS80 +step +proj=unitconvert +xy_in=rad " - "+z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=pipeline +step +proj=axisswap +order=2,1 +step " + "+proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m " + "+step +proj=cart +ellps=GRS80 +step +proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector +step +inv " + "+proj=cart +ellps=GRS80 +step +proj=unitconvert +xy_in=rad " + "+z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); } // --------------------------------------------------------------------------- @@ -4930,13 +4938,15 @@ TEST(operation, geogCRS_to_geocentricCRS_different_datum_context) { EXPECT_EQ(list[0]->nameStr(), "Conversion from ITRF2000 (geog3D) to ITRF2000 (geocentric) + " "ITRF2000 to ITRF2005 (1)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=pipeline +step +proj=axisswap +order=2,1 +step " - "+proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m " - "+step +proj=cart +ellps=GRS80 +step +proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=pipeline +step +proj=axisswap +order=2,1 +step " + "+proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m " + "+step +proj=cart +ellps=GRS80 +step +proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector"); } // --------------------------------------------------------------------------- @@ -4954,13 +4964,15 @@ TEST(operation, geocentricCRS_to_geogCRS_different_datum_context) { EXPECT_EQ(list[0]->nameStr(), "ITRF2000 to ITRF2005 (1) + " "Conversion from ITRF2005 (geocentric) to ITRF2005 (geog3D)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=pipeline +step +proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector +step +inv " - "+proj=cart +ellps=GRS80 +step +proj=unitconvert +xy_in=rad " - "+z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=pipeline +step +proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector +step +inv " + "+proj=cart +ellps=GRS80 +step +proj=unitconvert +xy_in=rad " + "+z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); } // --------------------------------------------------------------------------- @@ -4984,21 +4996,23 @@ TEST(operation, esri_projectedCRS_to_geogCRS_with_ITRF_intermediate_context) { "(geocentric) + Inverse of ITRF2000 to NAD83(CORS96) (1) + " "ITRF2000 to ITRF2005 (1) + " "Conversion from ITRF2005 (geocentric) to ITRF2005 (geog3D)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +z_in=us-ft " - "+xy_out=m +z_out=m +step +inv +proj=lcc +lat_0=33.75 +lon_0=-79 " - "+lat_1=34.3333333333333 +lat_2=36.1666666666667 " - "+x_0=609601.219202438 +y_0=0 +ellps=GRS80 +step +proj=cart " - "+ellps=GRS80 +step +inv +proj=helmert +x=0.9956 +y=-1.9013 " - "+z=-0.5215 +rx=0.025915 +ry=0.009426 +rz=0.011599 +s=0.00062 " - "+dx=0.0007 +dy=-0.0007 +dz=0.0005 +drx=6.7e-05 +dry=-0.000757 " - "+drz=-5.1e-05 +ds=-0.00018 +t_epoch=1997 " - "+convention=coordinate_frame +step +proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector +step +inv +proj=cart " - "+ellps=GRS80 +step +proj=unitconvert +xy_in=rad +z_in=m " - "+xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +z_in=us-ft " + "+xy_out=m +z_out=m +step +inv +proj=lcc +lat_0=33.75 +lon_0=-79 " + "+lat_1=34.3333333333333 +lat_2=36.1666666666667 " + "+x_0=609601.219202438 +y_0=0 +ellps=GRS80 +step +proj=cart " + "+ellps=GRS80 +step +inv +proj=helmert +x=0.9956 +y=-1.9013 " + "+z=-0.5215 +rx=0.025915 +ry=0.009426 +rz=0.011599 +s=0.00062 " + "+dx=0.0007 +dy=-0.0007 +dz=0.0005 +drx=6.7e-05 +dry=-0.000757 " + "+drz=-5.1e-05 +ds=-0.00018 +t_epoch=1997 " + "+convention=coordinate_frame +step +proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector +step +inv +proj=cart " + "+ellps=GRS80 +step +proj=unitconvert +xy_in=rad +z_in=m " + "+xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); } // --------------------------------------------------------------------------- diff --git a/test/unit/test_primitives.hpp b/test/unit/test_primitives.hpp new file mode 100644 index 00000000..86e52d0a --- /dev/null +++ b/test/unit/test_primitives.hpp @@ -0,0 +1,99 @@ +/****************************************************************************** + * + * Project: PROJ + * Purpose: Test ISO19111:2018 implementation + * Author: Even Rouault + * + ****************************************************************************** + * Copyright (c) 2018, Even Rouault + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + ****************************************************************************/ + +#include "gtest_include.h" + +#ifndef FROM_PROJ_CPP +#define FROM_PROJ_CPP +#endif + +#include "proj/internal/internal.hpp" + +#include +#include + +using namespace osgeo::proj::internal; + +static ::testing::AssertionResult ComparePROJString(const char* m_expr, + const char* n_expr, + const std::string& m, + const std::string& n) { + //if (m == n) return ::testing::AssertionSuccess(); + auto mTokens = split(m, ' '); + auto nTokens = split(n, ' '); + if( mTokens.size() == nTokens.size() ) + { + bool success = true; + for( size_t i = 0; i < mTokens.size(); i++ ) + { + auto mSubTokens = split(mTokens[i], '='); + auto nSubTokens = split(nTokens[i], '='); + if( mSubTokens.size() != nSubTokens.size() ) { + success = false; + break; + } + if( mSubTokens.size() == 2 && nSubTokens.size() == 2 ) { + if( mSubTokens[0] != nSubTokens[0] ) { + success = false; + break; + } + double mValue = 0.0; + bool mIsDouble = false; + try { + mValue = c_locale_stod(mSubTokens[1]); + mIsDouble = true; + } catch( const std::exception &) {} + double nValue = 0.0; + bool nIsDouble = false; + try { + nValue = c_locale_stod(nSubTokens[1]); + nIsDouble = true; + } catch( const std::exception &) {} + if( mIsDouble != nIsDouble ) { + success = false; + break; + } + if( mIsDouble ) { + success = std::abs(mValue - nValue) <= 1e-14 * std::abs(mValue); + } else { + success = mSubTokens[1] == nSubTokens[1]; + } + if( !success ) { + break; + } + } + } + + if( success ) { + return ::testing::AssertionSuccess(); + } + } + + return ::testing::AssertionFailure() << m_expr << " and " << n_expr + << " (" << m << " and " << n << ") are different"; +} -- cgit v1.2.3