diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-08-17 10:58:08 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-08-17 12:15:53 +0200 |
| commit | cad1c5cf61fc00759bf4ad17b0b34f57f4945de6 (patch) | |
| tree | 764439efa0cd35a6f1040838ea669d463a07c4bc /src | |
| parent | 8d0500b325d12b047797a60e3c13d4b473fae987 (diff) | |
| download | PROJ-cad1c5cf61fc00759bf4ad17b0b34f57f4945de6.tar.gz PROJ-cad1c5cf61fc00759bf4ad17b0b34f57f4945de6.zip | |
PROJJSON: rename file as projjson.schema.json, and add versionning to it and to exported PROJJSON strings
Diffstat (limited to 'src')
| -rw-r--r-- | src/iso19111/c_api.cpp | 4 | ||||
| -rw-r--r-- | src/iso19111/io.cpp | 21 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index d4813091..d27b8800 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -1335,6 +1335,8 @@ const char *proj_as_proj_string(PJ_CONTEXT *ctx, const PJ *obj, * <li>MULTILINE=YES/NO. Defaults to YES</li> * <li>INDENTATION_WIDTH=number. Defauls to 2 (when multiline output is * on).</li> + * <li>SCHEMA=string. URL to PROJJSON schema. Can be set to empty string to + * disable it.</li> * </ul> * @return a string, or NULL in case of error. * @@ -1359,6 +1361,8 @@ const char *proj_as_projjson(PJ_CONTEXT *ctx, const PJ *obj, formatter->setMultiLine(ci_equal(value, "YES")); } else if ((value = getOptionValue(*iter, "INDENTATION_WIDTH="))) { formatter->setIndentationWidth(std::atoi(value)); + } else if ((value = getOptionValue(*iter, "SCHEMA="))) { + formatter->setSchema(value); } else { std::string msg("Unknown option :"); msg += *iter; diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index 9f4f6061..5ccd9642 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -86,6 +86,10 @@ 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.1/projjson.schema.json" //! @endcond #if 0 @@ -9103,6 +9107,7 @@ struct JSONFormatter::Private { bool allowIDInImmediateChild_ = false; bool omitTypeInImmediateChild_ = false; bool abridgedTransformation_ = false; + std::string schema_ = PROJJSON_CURRENT_VERSION; std::string result_{}; @@ -9148,6 +9153,17 @@ JSONFormatter &JSONFormatter::setIndentationWidth(int width) noexcept { // --------------------------------------------------------------------------- +/** \brief Set the value of the "$schema" key in the top level object. + * + * If set to empty string, it will not be written. + */ +JSONFormatter &JSONFormatter::setSchema(const std::string &schema) noexcept { + d->schema_ = schema; + return *this; +} + +// --------------------------------------------------------------------------- + //! @cond Doxygen_Suppress JSONFormatter::JSONFormatter() : d(internal::make_unique<Private>()) {} @@ -9188,6 +9204,11 @@ JSONFormatter::ObjectContext::ObjectContext(JSONFormatter &formatter, const char *objectType, bool hasId) : m_formatter(formatter) { m_formatter.d->writer_.StartObj(); + if (m_formatter.d->outputIdStack_.size() == 1 && + !m_formatter.d->schema_.empty()) { + m_formatter.d->writer_.AddObjKey("$schema"); + m_formatter.d->writer_.Add(m_formatter.d->schema_); + } if (objectType && !m_formatter.d->omitTypeInImmediateChild_) { m_formatter.d->writer_.AddObjKey("type"); m_formatter.d->writer_.Add(objectType); |
