GEOS 3.10.1
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
28namespace geos {
29namespace geom {
30class Coordinate;
31class GeometryCollection;
32class Point;
33class LineString;
34class LinearRing;
35class Polygon;
36class MultiPoint;
37class MultiLineString;
38class MultiPolygon;
39class PrecisionModel;
40}
41}
42
43namespace geos {
44namespace io {
45
50class GEOS_DLL GeoJSONReader {
51public:
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
76private:
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: geos.h:40