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