Skip to content

Commit

Permalink
projinfo: support -k datum
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 7, 2020
1 parent 206a45d commit 6426bcb
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/source/apps/projinfo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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.
Expand Down
60 changes: 59 additions & 1 deletion src/apps/projinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] | "
Expand Down Expand Up @@ -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] == '"' &&
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions test/cli/testprojinfo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions test/cli/testprojinfo_out.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6426bcb

Please sign in to comment.