diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-01-07 15:32:47 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2020-01-07 15:32:47 +0100 |
| commit | 6426bcbd3605bf8cd6ae5c7869931fa89a26d641 (patch) | |
| tree | db72943fd44838b4d911c50d3161104611011040 | |
| parent | 206a45de20b4936efa0e216fce6addd768881508 (diff) | |
| download | PROJ-6426bcbd3605bf8cd6ae5c7869931fa89a26d641.tar.gz PROJ-6426bcbd3605bf8cd6ae5c7869931fa89a26d641.zip | |
projinfo: support -k datum
| -rw-r--r-- | docs/source/apps/projinfo.rst | 4 | ||||
| -rw-r--r-- | src/apps/projinfo.cpp | 60 | ||||
| -rwxr-xr-x | test/cli/testprojinfo | 20 | ||||
| -rw-r--r-- | test/cli/testprojinfo_out.dist | 35 |
4 files changed, 116 insertions, 3 deletions
diff --git a/docs/source/apps/projinfo.rst b/docs/source/apps/projinfo.rst index 2715f687..d1889844 100644 --- a/docs/source/apps/projinfo.rst +++ b/docs/source/apps/projinfo.rst @@ -16,7 +16,7 @@ Synopsis ******** | **projinfo** - | [-o formats] [-k crs|operation|ellipsoid] [--summary] [-q] + | [-o formats] [-k crs|operation|datum|ellipsoid] [--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] @@ -80,7 +80,7 @@ The following control parameters can appear in any order: .. note:: Before PROJ 6.3.0, WKT1:GDAL was implicitly calling --boundcrs-to-wgs84. This is no longer the case. -.. option:: -k crs|operation|ellipsoid +.. option:: -k crs|operation|datum|ellipsoid When used to query a single object with a AUTHORITY:CODE, determines the (k)ind of the object in case there are CRS, coordinate operations or ellipsoids with the same CODE. diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index c1139564..09b17b31 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -78,7 +78,7 @@ struct OutputOptions { static void usage() { std::cerr - << "usage: projinfo [-o formats] [-k crs|operation|ellipsoid] " + << "usage: projinfo [-o formats] [-k crs|operation|datum|ellipsoid] " "[--summary] [-q]" << std::endl << " ([--area name_or_code] | " @@ -184,6 +184,9 @@ static BaseObjectNNPtr buildObject( } else if (kind == "ellipsoid" && tokens.size() == 2) { auto urn = "urn:ogc:def:ellipsoid:" + tokens[0] + "::" + tokens[1]; obj = createFromUserInput(urn, dbContext).as_nullable(); + } else if (kind == "datum" && tokens.size() == 2) { + auto urn = "urn:ogc:def:datum:" + tokens[0] + "::" + tokens[1]; + obj = createFromUserInput(urn, dbContext).as_nullable(); } else { // Convenience to be able to use C escaped strings... if (l_user_string.size() > 2 && l_user_string[0] == '"' && @@ -205,6 +208,59 @@ static BaseObjectNNPtr buildObject( } } } + } else if (dbContext && !kind.empty() && kind != "crs" && + l_user_string.find(':') == std::string::npos) { + std::vector<AuthorityFactory::ObjectType> allowedTypes; + if (kind == "operation") + allowedTypes.push_back( + AuthorityFactory::ObjectType::COORDINATE_OPERATION); + else if (kind == "ellipsoid") + allowedTypes.push_back( + AuthorityFactory::ObjectType::ELLIPSOID); + else if (kind == "datum") + allowedTypes.push_back(AuthorityFactory::ObjectType::DATUM); + constexpr size_t limitResultCount = 10; + auto factory = AuthorityFactory::create(NN_NO_CHECK(dbContext), + std::string()); + for (int pass = 0; pass <= 1; ++pass) { + const bool approximateMatch = (pass == 1); + auto res = factory->createObjectsFromName( + l_user_string, allowedTypes, approximateMatch, + limitResultCount); + if (res.size() == 1) { + obj = res.front().as_nullable(); + } else { + for (const auto &l_obj : res) { + if (Identifier::isEquivalentName( + l_obj->nameStr().c_str(), + l_user_string.c_str())) { + obj = l_obj.as_nullable(); + break; + } + } + if (obj) { + break; + } + } + if (res.size() > 1) { + std::string msg("several objects matching this name: "); + bool first = true; + for (const auto &l_obj : res) { + if (msg.size() > 200) { + msg += ", ..."; + break; + } + if (!first) { + msg += ", "; + } + first = false; + msg += l_obj->nameStr(); + } + std::cerr << context << ": " << msg << std::endl; + std::exit(1); + } + } + } else { obj = createFromUserInput(l_user_string, dbContext).as_nullable(); @@ -863,6 +919,8 @@ int main(int argc, char **argv) { objectKind = "operation"; } else if (ci_equal(kind, "ellipsoid")) { objectKind = "ellipsoid"; + } else if (ci_equal(kind, "datum")) { + objectKind = "datum"; } else { std::cerr << "Unrecognized value for option -k: " << kind << std::endl; diff --git a/test/cli/testprojinfo b/test/cli/testprojinfo index 4ce5e90c..b9c452fb 100755 --- a/test/cli/testprojinfo +++ b/test/cli/testprojinfo @@ -155,6 +155,26 @@ echo 'Testing -s "GDA2020" -t "AHD height" --grid-check none -o PROJ --spatial-t $EXE -s "GDA2020" -t "AHD height" --grid-check none -o PROJ --spatial-test intersects >>${OUT} 2>&1 echo "" >>${OUT} +echo 'Testing -k ellipsoid WGS84' >> ${OUT} +$EXE -k ellipsoid WGS84 >>${OUT} 2>&1 +echo "" >>${OUT} + +echo 'Testing -k ellipsoid EPSG:7030' >> ${OUT} +$EXE -k ellipsoid EPSG:7030 >>${OUT} 2>&1 +echo "" >>${OUT} + +echo 'Testing -k datum WGS84' >> ${OUT} +$EXE -k datum WGS84 >>${OUT} 2>&1 +echo "" >>${OUT} + +echo 'Testing -k datum EPSG:6326' >> ${OUT} +$EXE -k datum EPSG:6326 >>${OUT} 2>&1 +echo "" >>${OUT} + +echo 'Testing -k operation EPSG:8457 -o PROJ -q' >> ${OUT} +$EXE -k operation EPSG:8457 -o PROJ -q >>${OUT} 2>&1 +echo "" >>${OUT} + # do 'diff' with distribution results echo "diff ${OUT} with testprojinfo_out.dist" diff -u ${OUT} ${TEST_CLI_DIR}/testprojinfo_out.dist diff --git a/test/cli/testprojinfo_out.dist b/test/cli/testprojinfo_out.dist index afadbd27..36f23dd9 100644 --- a/test/cli/testprojinfo_out.dist +++ b/test/cli/testprojinfo_out.dist @@ -1096,3 +1096,38 @@ DERIVED_FROM(EPSG):8451, GDA2020 to AHD height (1), 0.03 m, Australia Christmas PROJ string: +proj=pipeline +step +inv +proj=vgridshift +grids=AUSGeoid2020_20180201.gtx +multiplier=1 +Testing -k ellipsoid WGS84 +PROJ string: ++ellps=WGS84 + +WKT2:2019 string: +ELLIPSOID["WGS 84",6378137,298.257223563, + LENGTHUNIT["metre",1], + ID["EPSG",7030]] + +Testing -k ellipsoid EPSG:7030 +PROJ string: ++ellps=WGS84 + +WKT2:2019 string: +ELLIPSOID["WGS 84",6378137,298.257223563, + LENGTHUNIT["metre",1], + ID["EPSG",7030]] + +Testing -k datum WGS84 +WKT2:2019 string: +DATUM["World Geodetic System 1984", + ELLIPSOID["WGS 84",6378137,298.257223563, + LENGTHUNIT["metre",1]], + ID["EPSG",6326]] + +Testing -k datum EPSG:6326 +WKT2:2019 string: +DATUM["World Geodetic System 1984", + ELLIPSOID["WGS 84",6378137,298.257223563, + LENGTHUNIT["metre",1]], + ID["EPSG",6326]] + +Testing -k operation EPSG:8457 -o PROJ -q ++proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=bessel +step +proj=helmert +x=674.374 +y=15.056 +z=405.346 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1 + |
