GEOS  3.11.0
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 
32 namespace geos {
33 namespace geom {
34 class Geometry;
35 }
36 }
37 
38 namespace geos {
39 namespace io {
40 
41 class GEOS_DLL GeoJSONValue {
42 
43 private:
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 
60 public:
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 
91 class GEOS_DLL GeoJSONFeature {
92 
93 public:
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(GeoJSONFeature const& other);
102 
103  GeoJSONFeature(GeoJSONFeature&& other);
104 
105  GeoJSONFeature& operator=(const GeoJSONFeature&);
106 
107  GeoJSONFeature& operator=(GeoJSONFeature&&);
108 
109  const geom::Geometry* getGeometry() const;
110 
111  const std::map<std::string, GeoJSONValue>& getProperties() const;
112 
113 private:
114 
115  std::unique_ptr<geom::Geometry> geometry;
116 
117  std::map<std::string, GeoJSONValue> properties;
118 
119 };
120 
121 class GEOS_DLL GeoJSONFeatureCollection {
122 
123 public:
124 
125  GeoJSONFeatureCollection(const std::vector<GeoJSONFeature>& f);
126 
127  GeoJSONFeatureCollection(std::vector<GeoJSONFeature>&& f);
128 
129  const std::vector<GeoJSONFeature>& getFeatures() const;
130 
131 private:
132 
133  std::vector<GeoJSONFeature> features;
134 
135 };
136 
137 } // namespace geos::io
138 } // namespace geos
139 
140 #ifdef _MSC_VER
141 #pragma warning(pop)
142 #endif
143 
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25