GEOS  3.10.0
GeoJSONReader.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_GEOJSONREADER_H
16 #define GEOS_IO_GEOJSONREADER_H
17 
18 #include <geos/export.h>
19 
20 #include <geos/io/GeoJSON.h>
21 #include <geos/geom/GeometryFactory.h>
22 #include <geos/geom/CoordinateSequence.h>
23 #include <geos/geom/Geometry.h>
24 #include <string>
25 #include "geos/vend/include_nlohmann_json.hpp"
26 
27 // Forward declarations
28 namespace geos {
29 namespace geom {
30 class Coordinate;
31 class GeometryCollection;
32 class Point;
33 class LineString;
34 class LinearRing;
35 class Polygon;
36 class MultiPoint;
37 class MultiLineString;
38 class MultiPolygon;
39 class PrecisionModel;
40 }
41 }
42 
43 namespace geos {
44 namespace io {
45 
50 class GEOS_DLL GeoJSONReader {
51 public:
52 
62 
68 
69  ~GeoJSONReader() = default;
70 
72  std::unique_ptr<geom::Geometry> read(const std::string& geoJsonText) const;
73 
74  GeoJSONFeatureCollection readFeatures(const std::string& geoJsonText) const;
75 
76 private:
77 
78  const geom::GeometryFactory& geometryFactory;
79 
80  std::unique_ptr<geom::Geometry> readFeatureForGeometry(const geos_nlohmann::json& j) const;
81 
82  GeoJSONFeature readFeature(const geos_nlohmann::json& j) const;
83 
84  std::map<std::string, GeoJSONValue> readProperties(const geos_nlohmann::json& p) const;
85 
86  GeoJSONValue readProperty(const geos_nlohmann::json& p) const;
87 
88  std::unique_ptr<geom::Geometry> readFeatureCollectionForGeometry(
89  const geos_nlohmann::json& j) const;
90 
91  GeoJSONFeatureCollection readFeatureCollection(
92  const geos_nlohmann::json& j) const;
93 
94  std::unique_ptr<geom::Geometry> readGeometry(
95  const geos_nlohmann::json& j) const;
96 
97  std::unique_ptr<geom::Point> readPoint(const geos_nlohmann::json& j) const;
98 
99  geom::Coordinate readCoordinate(const std::vector<double>& coords) const;
100 
101  std::unique_ptr<geom::LineString> readLineString(
102  const geos_nlohmann::json& j) const;
103 
104  std::unique_ptr<geom::Polygon> readPolygon(
105  const geos_nlohmann::json& j) const;
106 
107  std::unique_ptr<geom::Polygon> readPolygon(
108  const std::vector<std::vector<std::vector<double>>>& c) const;
109 
110  std::unique_ptr<geom::MultiPoint> readMultiPoint(
111  const geos_nlohmann::json& j) const;
112 
113  std::unique_ptr<geom::MultiLineString> readMultiLineString(
114  const geos_nlohmann::json& j) const;
115 
116  std::unique_ptr<geom::MultiPolygon> readMultiPolygon(
117  const geos_nlohmann::json& j) const;
118 
119  std::unique_ptr<geom::GeometryCollection> readGeometryCollection(
120  const geos_nlohmann::json& j) const;
121 
122 };
123 
124 } // namespace io
125 } // namespace geos
126 
127 #endif // #ifndef GEOS_IO_GEOJSONREADER_H
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
GeoJSON reader class; see also GeoJSONWriter.
Definition: GeoJSONReader.h:50
GeoJSONReader(const geom::GeometryFactory &gf)
Inizialize parser with given GeometryFactory.
GeoJSONReader()
Inizialize parser with default GeometryFactory.
std::unique_ptr< geom::Geometry > read(const std::string &geoJsonText) const
Parse a GeoJSON string returning a Geometry.
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26