aboutsummaryrefslogtreecommitdiff
path: root/src/iso19111
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-09-14 22:03:48 +0200
committerGitHub <noreply@github.com>2021-09-14 22:03:48 +0200
commit47fb85bdf0e45bf5660e0b1dbde7b76f8824a87a (patch)
tree29373bee072524c43091b0b0597d9bd1a74d3006 /src/iso19111
parent92ca1a9455cdd136aaaeb1dbb0d8d867020e70c6 (diff)
parentbca0a82921594c675ed1212f54e032f19004ee82 (diff)
downloadPROJ-47fb85bdf0e45bf5660e0b1dbde7b76f8824a87a.tar.gz
PROJ-47fb85bdf0e45bf5660e0b1dbde7b76f8824a87a.zip
Merge pull request #2850 from rouault/projjson_0_4
PROJJSON: support additional properties allowed in id object (version, authority_citation, uri) for parity with WKT2:2019
Diffstat (limited to 'src/iso19111')
-rw-r--r--src/iso19111/crs.cpp7
-rw-r--r--src/iso19111/io.cpp46
-rw-r--r--src/iso19111/metadata.cpp26
3 files changed, 61 insertions, 18 deletions
diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp
index be593878..598cedad 100644
--- a/src/iso19111/crs.cpp
+++ b/src/iso19111/crs.cpp
@@ -5528,13 +5528,6 @@ void BoundCRS::_exportToJSON(
{
auto writer = formatter->writer();
const auto &l_name = nameStr();
- if ((formatter->outputUsage(true) && !domains().empty()) ||
- (formatter->outputId() && !identifiers().empty()) ||
- !remarks().empty() ||
- (!l_name.empty() && l_name != d->baseCRS()->nameStr())) {
- // Only upgrades to v0.3 schema if needed
- formatter->setSchema(io::JSONFormatter::PROJJSON_v0_3);
- }
auto objectContext(formatter->MakeObjectContext("BoundCRS", false));
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp
index 5d7e951e..d3928a86 100644
--- a/src/iso19111/io.cpp
+++ b/src/iso19111/io.cpp
@@ -35,6 +35,7 @@
#include <cctype>
#include <cmath>
#include <cstring>
+#include <limits>
#include <list>
#include <locale>
#include <map>
@@ -106,14 +107,10 @@ NS_PROJ_START
namespace io {
//! @cond Doxygen_Suppress
-const char *JSONFormatter::PROJJSON_v0_2 =
- "https://proj.org/schemas/v0.2/projjson.schema.json";
+const char *JSONFormatter::PROJJSON_v0_4 =
+ "https://proj.org/schemas/v0.4/projjson.schema.json";
-const char *JSONFormatter::PROJJSON_v0_3 =
- "https://proj.org/schemas/v0.3/projjson.schema.json";
-
-// v0.2 is our base version. We only upgrade to 0.3 for usage node in BoundCRS
-#define PROJJSON_DEFAULT_VERSION JSONFormatter::PROJJSON_v0_2
+#define PROJJSON_DEFAULT_VERSION JSONFormatter::PROJJSON_v0_4
//! @endcond
@@ -5398,6 +5395,36 @@ IdentifierNNPtr JSONParser::buildId(const json &j, bool removeInverseOf) {
} else {
throw ParsingException("Unexpected type for value of \"code\"");
}
+
+ if (j.contains("version")) {
+ auto versionJ = j["version"];
+ std::string version;
+ if (versionJ.is_string()) {
+ version = versionJ.get<std::string>();
+ } else if (versionJ.is_number()) {
+ const double dblVersion = versionJ.get<double>();
+ if (dblVersion >= std::numeric_limits<int>::min() &&
+ dblVersion <= std::numeric_limits<int>::max() &&
+ static_cast<int>(dblVersion) == dblVersion) {
+ version = internal::toString(static_cast<int>(dblVersion));
+ } else {
+ version = internal::toString(dblVersion);
+ }
+ } else {
+ throw ParsingException("Unexpected type for value of \"version\"");
+ }
+ propertiesId.set(Identifier::VERSION_KEY, version);
+ }
+
+ if (j.contains("authority_citation")) {
+ propertiesId.set(Identifier::AUTHORITY_KEY,
+ getString(j, "authority_citation"));
+ }
+
+ if (j.contains("uri")) {
+ propertiesId.set(Identifier::URI_KEY, getString(j, "uri"));
+ }
+
return Identifier::create(code, propertiesId);
}
@@ -10709,10 +10736,7 @@ JSONFormatter &JSONFormatter::setIndentationWidth(int width) noexcept {
* If set to empty string, it will not be written.
*/
JSONFormatter &JSONFormatter::setSchema(const std::string &schema) noexcept {
- // Upgrade only to v0.3 if the default was v0.2
- if (schema != PROJJSON_v0_3 || d->schema_ == PROJJSON_v0_2) {
- d->schema_ = schema;
- }
+ d->schema_ = schema;
return *this;
}
diff --git a/src/iso19111/metadata.cpp b/src/iso19111/metadata.cpp
index e8ce37c6..fc1b103f 100644
--- a/src/iso19111/metadata.cpp
+++ b/src/iso19111/metadata.cpp
@@ -41,6 +41,7 @@
#include "proj_json_streaming_writer.hpp"
#include <algorithm>
+#include <limits>
#include <memory>
#include <string>
#include <vector>
@@ -1114,6 +1115,31 @@ void Identifier::_exportToJSON(JSONFormatter *formatter) const {
} catch (const std::exception &) {
writer->Add(l_code);
}
+
+ if (version().has_value()) {
+ const auto l_version = *(version());
+ writer->AddObjKey("version");
+ try {
+ const double dblVersion = c_locale_stod(l_version);
+ if (dblVersion >= std::numeric_limits<int>::min() &&
+ dblVersion <= std::numeric_limits<int>::max() &&
+ static_cast<int>(dblVersion) == dblVersion) {
+ writer->Add(static_cast<int>(dblVersion));
+ } else {
+ writer->Add(dblVersion);
+ }
+ } catch (const std::exception &) {
+ writer->Add(l_version);
+ }
+ }
+ if (authority().has_value() && *(authority()->title()) != l_codeSpace) {
+ writer->AddObjKey("authority_citation");
+ writer->Add(*(authority()->title()));
+ }
+ if (uri().has_value()) {
+ writer->AddObjKey("uri");
+ writer->Add(*(uri()));
+ }
}
}