Skip to content

Commit

Permalink
Merge pull request #2371 from rouault/epsg10_part2
Browse files Browse the repository at this point in the history
EPSG v10 update part 2: ingest DatumEnsemble from the database
  • Loading branch information
rouault authored Nov 1, 2020
2 parents cccd65e + 119888b commit 3b7c3a6
Show file tree
Hide file tree
Showing 13 changed files with 481 additions and 98 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|datum|ellipsoid] [--summary] [-q]
| [-o formats] [-k crs|operation|datum|ensemble|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 @@ -86,7 +86,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|datum|ellipsoid
.. option:: -k crs|operation|datum|ensemble|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
14 changes: 14 additions & 0 deletions include/proj/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,8 @@ class PROJ_GCC_DLL AuthorityFactory {
DYNAMIC_GEODETIC_REFERENCE_FRAME,
/** Object of type datum::DynamicVerticalReferenceFrame */
DYNAMIC_VERTICAL_REFERENCE_FRAME,
/** Object of type datum::DatumEnsemble */
DATUM_ENSEMBLE,
};

PROJ_DLL std::set<std::string>
Expand Down Expand Up @@ -1225,6 +1227,18 @@ class PROJ_GCC_DLL AuthorityFactory {

private:
PROJ_OPAQUE_PRIVATE_DATA

PROJ_INTERNAL void
createGeodeticDatumOrEnsemble(const std::string &code,
datum::GeodeticReferenceFramePtr &outDatum,
datum::DatumEnsemblePtr &outDatumEnsemble,
bool turnEnsembleAsDatum) const;

PROJ_INTERNAL void
createVerticalDatumOrEnsemble(const std::string &code,
datum::VerticalReferenceFramePtr &outDatum,
datum::DatumEnsemblePtr &outDatumEnsemble,
bool turnEnsembleAsDatum) const;
};

// ---------------------------------------------------------------------------
Expand Down
18 changes: 12 additions & 6 deletions src/apps/projinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ struct OutputOptions {

static void usage() {
std::cerr
<< "usage: projinfo [-o formats] [-k crs|operation|datum|ellipsoid] "
<< "usage: projinfo [-o formats] "
"[-k crs|operation|datum|ensemble|ellipsoid] "
"[--summary] [-q]"
<< std::endl
<< " ([--area name_or_code] | "
Expand Down Expand Up @@ -184,11 +185,11 @@ static BaseObjectNNPtr buildObject(
auto urn = "urn:ogc:def:coordinateOperation:" + tokens[0] + "::" +
tokens[1];
obj = createFromUserInput(urn, dbContext).as_nullable();
} 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];
} else if ((kind == "ellipsoid" || kind == "datum" ||
kind == "ensemble") &&
tokens.size() == 2) {
auto urn =
"urn:ogc:def:" + kind + ":" + tokens[0] + "::" + tokens[1];
obj = createFromUserInput(urn, dbContext).as_nullable();
} else {
// Convenience to be able to use C escaped strings...
Expand Down Expand Up @@ -222,6 +223,9 @@ static BaseObjectNNPtr buildObject(
AuthorityFactory::ObjectType::ELLIPSOID);
else if (kind == "datum")
allowedTypes.push_back(AuthorityFactory::ObjectType::DATUM);
else if (kind == "ensemble")
allowedTypes.push_back(
AuthorityFactory::ObjectType::DATUM_ENSEMBLE);
constexpr size_t limitResultCount = 10;
auto factory = AuthorityFactory::create(NN_NO_CHECK(dbContext),
std::string());
Expand Down Expand Up @@ -929,6 +933,8 @@ int main(int argc, char **argv) {
objectKind = "ellipsoid";
} else if (ci_equal(kind, "datum")) {
objectKind = "datum";
} else if (ci_equal(kind, "ensemble")) {
objectKind = "ensemble";
} else {
std::cerr << "Unrecognized value for option -k: " << kind
<< std::endl;
Expand Down
5 changes: 4 additions & 1 deletion src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ PJ *proj_create_from_database(PJ_CONTEXT *ctx, const char *auth_name,
codeStr, usePROJAlternativeGridNames != 0)
.as_nullable();
break;
case PJ_CATEGORY_DATUM_ENSEMBLE:
obj = factory->createDatumEnsemble(codeStr).as_nullable();
break;
}
return pj_obj_create(ctx, NN_NO_CHECK(obj));
} catch (const std::exception &e) {
Expand Down Expand Up @@ -916,7 +919,7 @@ convertPJObjectTypeToObjectType(PJ_TYPE type, bool &valid) {
break;

case PJ_TYPE_DATUM_ENSEMBLE:
cppType = AuthorityFactory::ObjectType::DATUM;
cppType = AuthorityFactory::ObjectType::DATUM_ENSEMBLE;
break;

case PJ_TYPE_TEMPORAL_DATUM:
Expand Down
8 changes: 8 additions & 0 deletions src/iso19111/datum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,14 @@ void DatumEnsemble::_exportToWKT(
formatter->startNode(io::WKTConstants::ENSEMBLEACCURACY, false);
formatter->add(positionalAccuracy()->value());
formatter->endNode();

// In theory, we should do the following, but currently the WKT grammar
// doesn't allow this
// ObjectUsage::baseExportToWKT(formatter);
if (formatter->outputId()) {
formatID(formatter);
}

formatter->endNode();
}
//! @endcond
Expand Down
Loading

0 comments on commit 3b7c3a6

Please sign in to comment.