From 31692d0c0667f26ea1975affeae161beabb279fd Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 18 Aug 2021 20:27:46 +0200 Subject: =?UTF-8?q?BoundCRS:=20accept=20importing/exporting=20in=20WKT2=20?= =?UTF-8?q?and=20PROJJSON=20the=20scope/area/extent/id=20attributes=20(fix?= =?UTF-8?q?es=C2=A0#2813)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For PROJJSON only, also accept the ``name`` attribute. --- src/iso19111/io.cpp | 54 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'src/iso19111/io.cpp') diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index ccbb0ffe..867e08ed 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -89,10 +89,6 @@ using json = nlohmann::json; //! @cond Doxygen_Suppress static const std::string emptyString{}; - -// If changing that value, change it in data/projjson.schema.json as well -#define PROJJSON_CURRENT_VERSION \ - "https://proj.org/schemas/v0.2/projjson.schema.json" //! @endcond #if 0 @@ -109,6 +105,18 @@ template<> nn()); - return BoundCRS::create(NN_NO_CHECK(sourceCRS), NN_NO_CHECK(targetCRS), - transformation); + return BoundCRS::create(buildProperties(node), NN_NO_CHECK(sourceCRS), + NN_NO_CHECK(targetCRS), transformation); } // --------------------------------------------------------------------------- @@ -5057,7 +5065,8 @@ class JSONParser { IdentifierNNPtr buildId(const json &j, bool removeInverseOf); static ObjectDomainPtr buildObjectDomain(const json &j); - PropertyMap buildProperties(const json &j, bool removeInverseOf = false); + PropertyMap buildProperties(const json &j, bool removeInverseOf = false, + bool nameRequired = true); GeographicCRSNNPtr buildGeographicCRS(const json &j); GeodeticCRSNNPtr buildGeodeticCRS(const json &j); @@ -5358,13 +5367,17 @@ IdentifierNNPtr JSONParser::buildId(const json &j, bool removeInverseOf) { // --------------------------------------------------------------------------- -PropertyMap JSONParser::buildProperties(const json &j, bool removeInverseOf) { +PropertyMap JSONParser::buildProperties(const json &j, bool removeInverseOf, + bool nameRequired) { PropertyMap map; - std::string name(getName(j)); - if (removeInverseOf && starts_with(name, "Inverse of ")) { - name = name.substr(strlen("Inverse of ")); + + if (j.contains("name") || nameRequired) { + std::string name(getName(j)); + if (removeInverseOf && starts_with(name, "Inverse of ")) { + name = name.substr(strlen("Inverse of ")); + } + map.set(IdentifiedObject::NAME_KEY, name); } - map.set(IdentifiedObject::NAME_KEY, name); if (j.contains("ids")) { auto idsJ = getArray(j, "ids"); @@ -5782,7 +5795,10 @@ BoundCRSNNPtr JSONParser::buildBoundCRS(const json &j) { nullptr, buildProperties(methodJ), parameters, values, std::vector()); - return BoundCRS::create(sourceCRS, targetCRS, transformation); + return BoundCRS::create(buildProperties(j, + /* removeInverseOf= */ false, + /* nameRequired=*/false), + sourceCRS, targetCRS, transformation); } // --------------------------------------------------------------------------- @@ -10529,7 +10545,7 @@ struct JSONFormatter::Private { bool allowIDInImmediateChild_ = false; bool omitTypeInImmediateChild_ = false; bool abridgedTransformation_ = false; - std::string schema_ = PROJJSON_CURRENT_VERSION; + std::string schema_ = PROJJSON_DEFAULT_VERSION; std::string result_{}; @@ -10580,7 +10596,10 @@ JSONFormatter &JSONFormatter::setIndentationWidth(int width) noexcept { * If set to empty string, it will not be written. */ JSONFormatter &JSONFormatter::setSchema(const std::string &schema) noexcept { - d->schema_ = schema; + // Upgrade only to v0.3 if the default was v0.2 + if (schema != PROJJSON_v0_3 || d->schema_ == PROJJSON_v0_2) { + d->schema_ = schema; + } return *this; } @@ -10604,8 +10623,9 @@ bool JSONFormatter::outputId() const { return d->outputIdStack_.back(); } // --------------------------------------------------------------------------- -bool JSONFormatter::outputUsage() const { - return outputId() && d->outputIdStack_.size() == 2; +bool JSONFormatter::outputUsage(bool calledBeforeObjectContext) const { + return outputId() && + d->outputIdStack_.size() == (calledBeforeObjectContext ? 1U : 2U); } // --------------------------------------------------------------------------- -- cgit v1.2.3