GEOS 3.10.1
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#ifndef GEOS_IO_GEOJSON_H
16#define GEOS_IO_GEOJSON_H
17
18#include <geos/export.h>
19
20#include <map>
21#include <vector>
22#include <string>
23#include <sstream>
24#include <cctype>
25#include <cstddef>
26#include <geos/geom/Geometry.h>
27
28#ifdef _MSC_VER
29#pragma warning(push)
30#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
31#endif
32
33namespace geos {
34namespace geom {
35class Geometry;
36}
37}
38
39namespace geos {
40namespace io {
41
42class GEOS_DLL GeoJSONValue {
43
44private:
45
46 enum class Type { NUMBER, STRING, NULLTYPE, BOOLEAN, OBJECT, ARRAY };
47
48 Type type;
49
50 union {
51 double d;
52 std::string s;
53 std::nullptr_t n;
54 bool b;
55 std::map<std::string, GeoJSONValue> o;
56 std::vector<GeoJSONValue> a;
57 };
58
59 void cleanup();
60
61public:
62
63 struct GeoJSONTypeError {};
64
65 GeoJSONValue(double);
66 GeoJSONValue(const std::string&);
67 GeoJSONValue();
68 GeoJSONValue(bool);
69 GeoJSONValue(const std::map<std::string, GeoJSONValue>&);
70 GeoJSONValue(const std::vector<GeoJSONValue>&);
71
72 ~GeoJSONValue();
73 GeoJSONValue(const GeoJSONValue&);
74 GeoJSONValue& operator=(const GeoJSONValue&);
75
76 double getNumber() const;
77 const std::string& getString() const;
78 std::nullptr_t getNull() const;
79 bool getBoolean() const;
80 const std::map<std::string, GeoJSONValue>& getObject() const;
81 const std::vector<GeoJSONValue>& getArray() const;
82
83 bool isNumber() const;
84 bool isString() const;
85 bool isNull() const;
86 bool isBoolean() const;
87 bool isObject() const;
88 bool isArray() const;
89
90};
91
92class GEOS_DLL GeoJSONFeature {
93
94public:
95
96 GeoJSONFeature(std::unique_ptr<geom::Geometry> g,
97 const std::map<std::string, GeoJSONValue>& p);
98
99 GeoJSONFeature(std::unique_ptr<geom::Geometry> g,
100 std::map<std::string, GeoJSONValue>&& p);
101
102 GeoJSONFeature(GeoJSONFeature const& other);
103
104 GeoJSONFeature(GeoJSONFeature&& other);
105
106 GeoJSONFeature& operator=(const GeoJSONFeature&);
107
108 GeoJSONFeature& operator=(GeoJSONFeature&&);
109
110 const geom::Geometry* getGeometry() const;
111
112 const std::map<std::string, GeoJSONValue>& getProperties() const;
113
114private:
115
116 std::unique_ptr<geom::Geometry> geometry;
117
118 std::map<std::string, GeoJSONValue> properties;
119
120};
121
122class GEOS_DLL GeoJSONFeatureCollection {
123
124public:
125
126 GeoJSONFeatureCollection(const std::vector<GeoJSONFeature>& f);
127
128 GeoJSONFeatureCollection(std::vector<GeoJSONFeature>&& f);
129
130 const std::vector<GeoJSONFeature>& getFeatures() const;
131
132private:
133
134 std::vector<GeoJSONFeature> features;
135
136};
137
138} // namespace geos::io
139} // namespace geos
140
141#ifdef _MSC_VER
142#pragma warning(pop)
143#endif
144
145#endif // #ifndef GEOS_IO_GEOJSON_H
Basic namespace for all GEOS functionalities.
Definition: geos.h:40