GEOS 3.14.0dev
GeoJSON.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2021 Jared Erickson
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/export.h>
18
19#include <map>
20#include <vector>
21#include <string>
22#include <sstream>
23#include <cctype>
24#include <cstddef>
25#include <geos/geom/Geometry.h>
26
27#ifdef _MSC_VER
28#pragma warning(push)
29#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
30#endif
31
32namespace geos {
33namespace geom {
34class Geometry;
35}
36}
37
38namespace geos {
39namespace io {
40
41class GEOS_DLL GeoJSONValue {
42
43private:
44
45 enum class Type { NUMBER, STRING, NULLTYPE, BOOLEAN, OBJECT, ARRAY };
46
47 Type type;
48
49 union {
50 double d;
51 std::string s;
52 std::nullptr_t n;
53 bool b;
54 std::map<std::string, GeoJSONValue> o;
55 std::vector<GeoJSONValue> a;
56 };
57
58 void cleanup();
59
60public:
61
62 struct GeoJSONTypeError {};
63
64 GeoJSONValue(double);
65 GeoJSONValue(const std::string&);
66 GeoJSONValue();
67 GeoJSONValue(bool);
68 GeoJSONValue(const std::map<std::string, GeoJSONValue>&);
69 GeoJSONValue(const std::vector<GeoJSONValue>&);
70
71 ~GeoJSONValue();
72 GeoJSONValue(const GeoJSONValue&);
73 GeoJSONValue& operator=(const GeoJSONValue&);
74
75 double getNumber() const;
76 const std::string& getString() const;
77 std::nullptr_t getNull() const;
78 bool getBoolean() const;
79 const std::map<std::string, GeoJSONValue>& getObject() const;
80 const std::vector<GeoJSONValue>& getArray() const;
81
82 bool isNumber() const;
83 bool isString() const;
84 bool isNull() const;
85 bool isBoolean() const;
86 bool isObject() const;
87 bool isArray() const;
88
89};
90
91class GEOS_DLL GeoJSONFeature {
92
93public:
94
95 GeoJSONFeature(std::unique_ptr<geom::Geometry> g,
96 const std::map<std::string, GeoJSONValue>& p);
97
98 GeoJSONFeature(std::unique_ptr<geom::Geometry> g,
99 std::map<std::string, GeoJSONValue>&& p);
100
101 GeoJSONFeature(std::unique_ptr<geom::Geometry> g,
102 const std::map<std::string, GeoJSONValue>& p,
103 const std::string& id);
104
105 GeoJSONFeature(std::unique_ptr<geom::Geometry> g,
106 std::map<std::string, GeoJSONValue>&& p, std::string id);
107
108 GeoJSONFeature(GeoJSONFeature const& other);
109
110 GeoJSONFeature(GeoJSONFeature&& other);
111
112 GeoJSONFeature& operator=(const GeoJSONFeature&);
113
114 GeoJSONFeature& operator=(GeoJSONFeature&&);
115
116 const geom::Geometry* getGeometry() const;
117
118 const std::map<std::string, GeoJSONValue>& getProperties() const;
119
120 const std::string& getId() const;
121
122private:
123
124 std::unique_ptr<geom::Geometry> geometry;
125
126 std::map<std::string, GeoJSONValue> properties;
127
128 std::string id;
129
130};
131
132class GEOS_DLL GeoJSONFeatureCollection {
133
134public:
135
136 GeoJSONFeatureCollection(const std::vector<GeoJSONFeature>& f);
137
138 GeoJSONFeatureCollection(std::vector<GeoJSONFeature>&& f);
139
140 const std::vector<GeoJSONFeature>& getFeatures() const;
141
142private:
143
144 std::vector<GeoJSONFeature> features;
145
146};
147
148} // namespace geos::io
149} // namespace geos
150
151#ifdef _MSC_VER
152#pragma warning(pop)
153#endif
154
Basic namespace for all GEOS functionalities.
Definition geos.h:39