GEOS 3.11.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#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
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:58
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
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: geos.h:39