Skip to content

Commit

Permalink
Merge pull request #3223 from OSGeo/backport-3221-to-9.0
Browse files Browse the repository at this point in the history
[Backport 9.0] PROJJSON parser: do not error out if a datum ensemble member is unknown in the database
  • Loading branch information
rouault committed Jun 5, 2022
2 parents 6833956 + 6c0ca06 commit 641e108
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6253,6 +6253,7 @@ DatumEnsembleNNPtr JSONParser::buildDatumEnsemble(const json &j) {
"Unexpected type for value of a \"members\" member");
}
auto datumName(getName(memberJ));
bool datumAdded = false;
if (dbContext_ && memberJ.contains("id")) {
auto id = getObject(memberJ, "id");
auto authority = getString(id, "authority");
Expand All @@ -6269,11 +6270,16 @@ DatumEnsembleNNPtr JSONParser::buildDatumEnsemble(const json &j) {
}
try {
datums.push_back(authFactory->createDatum(codeStr));
datumAdded = true;
} catch (const std::exception &) {
throw ParsingException("No Datum of code " + codeStr);
// Silently ignore, as this isn't necessary an error.
// If an older PROJ version parses a DatumEnsemble object of
// a more recent PROJ version where the datum ensemble got
// a new member, it might be unknown from the older PROJ.
}
continue;
} else if (dbContext_) {
}

if (dbContext_ && !datumAdded) {
auto authFactory = AuthorityFactory::create(NN_NO_CHECK(dbContext_),
std::string());
auto list = authFactory->createObjectsFromName(
Expand All @@ -6285,19 +6291,21 @@ DatumEnsembleNNPtr JSONParser::buildDatumEnsemble(const json &j) {
throw ParsingException(
"DatumEnsemble member is not a datum");
datums.push_back(NN_NO_CHECK(datum));
continue;
datumAdded = true;
}
}

// Fallback if no db match
if (hasEllipsoid) {
datums.emplace_back(GeodeticReferenceFrame::create(
buildProperties(memberJ),
buildEllipsoid(getObject(j, "ellipsoid")),
optional<std::string>(), PrimeMeridian::GREENWICH));
} else {
datums.emplace_back(
VerticalReferenceFrame::create(buildProperties(memberJ)));
if (!datumAdded) {
// Fallback if no db match
if (hasEllipsoid) {
datums.emplace_back(GeodeticReferenceFrame::create(
buildProperties(memberJ),
buildEllipsoid(getObject(j, "ellipsoid")),
optional<std::string>(), PrimeMeridian::GREENWICH));
} else {
datums.emplace_back(
VerticalReferenceFrame::create(buildProperties(memberJ)));
}
}
}
return DatumEnsemble::create(
Expand Down
14 changes: 14 additions & 0 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13643,6 +13643,13 @@ TEST(json_import, geographic_crs_with_datum_ensemble) {
" },\n"
" {\n"
" \"name\": \"World Geodetic System 1984 (G730)\"\n"
" },\n"
" {\n"
" \"name\": \"Some unknown ensemble with unknown id\",\n"
" \"id\": {\n"
" \"authority\": \"UNKNOWN\",\n"
" \"code\": 1234\n"
" }\n"
" }\n"
" ],\n"
" \"ellipsoid\": {\n"
Expand Down Expand Up @@ -13692,6 +13699,13 @@ TEST(json_import, geographic_crs_with_datum_ensemble) {
" \"authority\": \"EPSG\",\n"
" \"code\": 1152\n"
" }\n"
" },\n"
" {\n"
" \"name\": \"Some unknown ensemble with unknown id\",\n"
" \"id\": {\n"
" \"authority\": \"UNKNOWN\",\n"
" \"code\": 1234\n"
" }\n"
" }\n"
" ],\n"
" \"ellipsoid\": {\n"
Expand Down

0 comments on commit 641e108

Please sign in to comment.