From 4b5d1efe501e39240fcdaae5e7b8ef62fc7023df Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 5 Jun 2022 18:18:27 +0200 Subject: [PATCH] PROJJSON parser: do not error out if a datum ensemble member is unknown in the database Fix issue raised in https://github.com/opengeospatial/geoparquet/discussions/110 --- src/iso19111/io.cpp | 34 +++++++++++++++++++++------------- test/unit/test_io.cpp | 14 ++++++++++++++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 72430a1789..f951470b33 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -6328,6 +6328,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"); @@ -6344,11 +6345,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( @@ -6360,19 +6366,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(), 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(), PrimeMeridian::GREENWICH)); + } else { + datums.emplace_back( + VerticalReferenceFrame::create(buildProperties(memberJ))); + } } } return DatumEnsemble::create( diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 73b5e436be..27387be4a7 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -13809,6 +13809,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" @@ -13858,6 +13865,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"