diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-07-06 02:03:50 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-07-06 02:27:46 +0200 |
| commit | 17f0b0b3bc65ffba39bf6f22a12b2cc7fcb9bafd (patch) | |
| tree | 5993d701145e2117fb8598faa186312b98d54f00 /src/iso19111/common.cpp | |
| parent | 1da55c8be619a21153845607a553c9d1206bc792 (diff) | |
| download | PROJ-17f0b0b3bc65ffba39bf6f22a12b2cc7fcb9bafd.tar.gz PROJ-17f0b0b3bc65ffba39bf6f22a12b2cc7fcb9bafd.zip | |
Proof-of-concept of JSON export limited to PrimeMeridian (refs #1545)
Diffstat (limited to 'src/iso19111/common.cpp')
| -rw-r--r-- | src/iso19111/common.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/iso19111/common.cpp b/src/iso19111/common.cpp index d46da0da..f2a51032 100644 --- a/src/iso19111/common.cpp +++ b/src/iso19111/common.cpp @@ -236,6 +236,54 @@ void UnitOfMeasure::_exportToWKT( } formatter->endNode(); } + +// --------------------------------------------------------------------------- + +void UnitOfMeasure::_exportToJSON( + JSONFormatter *formatter) const // throw(FormattingException) +{ + auto &writer = formatter->writer(); + PROJ::CPLJSonStreamingWriter::ObjectContext objContext(writer); + writer.AddObjKey("type"); + const auto l_type = type(); + if (l_type == Type::LINEAR) { + writer.Add("LinearUnit"); + } else if (l_type == Type::ANGULAR) { + writer.Add("AngularUnit"); + } else if (l_type == Type::SCALE) { + writer.Add("ScaleUnit"); + } else if (l_type == Type::TIME) { + writer.Add("TimeUnit"); + } else if (l_type == Type::PARAMETRIC) { + writer.Add("ParametericUnit"); + } else { + writer.Add("Unit"); + } + + writer.AddObjKey("name"); + const auto &l_name = name(); + writer.Add(l_name); + + const auto &factor = conversionToSI(); + writer.AddObjKey("conversion_factor"); + writer.Add(factor, 15); + + const auto &l_codeSpace = codeSpace(); + if (!l_codeSpace.empty() && formatter->outputId()) { + writer.AddObjKey("id"); + PROJ::CPLJSonStreamingWriter::ObjectContext idContext(writer); + writer.AddObjKey("authority"); + writer.Add(l_codeSpace); + writer.AddObjKey("code"); + const auto &l_code = code(); + try { + writer.Add(std::stoi(l_code)); + } catch (const std::exception &) { + writer.Add(l_code); + } + } +} + //! @endcond // --------------------------------------------------------------------------- @@ -815,6 +863,23 @@ void IdentifiedObject::formatRemarks(WKTFormatter *formatter) const { // --------------------------------------------------------------------------- +void IdentifiedObject::formatID(JSONFormatter *formatter) const { + const auto &ids(identifiers()); + auto &writer = formatter->writer(); + if (ids.size() == 1) { + writer.AddObjKey("id"); + ids.front()->_exportToJSON(formatter); + } else if (!ids.empty()) { + writer.AddObjKey("ids"); + PROJ::CPLJSonStreamingWriter::ArrayContext arrayContext(writer); + for (const auto &id : ids) { + id->_exportToJSON(formatter); + } + } +} + +// --------------------------------------------------------------------------- + bool IdentifiedObject::_isEquivalentTo( const util::IComparable *other, util::IComparable::Criterion criterion) const { |
