GEOS 3.15.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
27namespace geos {
28namespace geom {
29class Coordinate;
30class GeometryCollection;
31class Point;
32class LineString;
33class LinearRing;
34class Polygon;
35class MultiPoint;
36class MultiLineString;
37class MultiPolygon;
38class PrecisionModel;
39}
40}
41
42namespace geos {
43namespace io {
44
49class GEOS_DLL GeoJSONReader {
50public:
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
75private:
76
77 const geom::GeometryFactory& geometryFactory;
78 mutable int parseDepth_ = 0;
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
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:220
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:71
GeoJSON reader class; see also GeoJSONWriter.
Definition GeoJSONReader.h:49
GeoJSONReader(const geom::GeometryFactory &gf)
Initialize parser with given GeometryFactory.
GeoJSONReader()
Initialize 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:38