Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
27db459c83
Geojson serialization draft
Signed-off-by: S. Kozyr <s.trump@gmail.com>
2025-03-25 10:08:14 +02:00
3 changed files with 84 additions and 0 deletions

View file

@ -10,6 +10,8 @@ set(SRC
serdes_binary.cpp
serdes_binary.hpp
serdes_binary_v8.hpp
serdes_geojson.cpp
serdes_geojson.hpp
serdes_gpx.cpp
serdes_gpx.hpp
type_utils.cpp

52
kml/serdes_geojson.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "kml/serdes_geojson.hpp"
#include "coding/serdes_json.hpp"
namespace kml
{
namespace geojson
{
struct GeoJsonFeature
{
DECLARE_VISITOR_AND_DEBUG_PRINT(GeoJsonFeature, visitor(m_type, "type"),
visitor(m_properties, "properties"))
bool operator==(GeoJsonFeature const & data) const
{
return m_type == data.m_type && m_properties == data.m_properties;
}
bool operator!=(GeoJsonFeature const & data) const { return !operator==(data); }
std::string m_type = "Feature";
std::map<std::string, std::string> m_properties;
};
struct GeoJsonData
{
DECLARE_VISITOR_AND_DEBUG_PRINT(GeoJsonData, visitor(m_type, "type"),
visitor(m_features, "features"))
bool operator==(GeoJsonData const & data) const
{
return m_type == data.m_type;
}
bool operator!=(GeoJsonData const & data) const { return !operator==(data); }
std::string m_type = "FeatureCollection";
std::list<GeoJsonFeature> m_features;
};
void GeojsonWriter::Write(FileData const & fileData)
{
GeoJsonData data;
coding::SerializerJson<Writer> ser(m_writer);
ser(data);
}
} // namespace geojson
} // namespace kml

30
kml/serdes_geojson.hpp Normal file
View file

@ -0,0 +1,30 @@
#pragma once
#include "kml/types.hpp"
#include "coding/writer.hpp"
#include "base/exception.hpp"
namespace kml
{
namespace geojson
{
class GeojsonWriter
{
public:
DECLARE_EXCEPTION(WriteGeojsonException, RootException);
explicit GeojsonWriter(Writer & writer)
: m_writer(writer)
{}
void Write(FileData const & fileData);
private:
Writer & m_writer;
};
} // namespace geojson
} // namespace kml