GeoJSONReader.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2021 Jared Erickson
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/io/GeoJSON.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/Geometry.h>
#include <string>
#include "geos/vend/include_nlohmann_json.hpp"
// Forward declarations
namespace geos {
namespace geom {
class Coordinate;
class GeometryCollection;
class Point;
class LineString;
class LinearRing;
class Polygon;
class MultiPoint;
class MultiLineString;
class MultiPolygon;
class PrecisionModel;
}
}
namespace geos {
namespace io {
class GEOS_DLL GeoJSONReader {
public:
GeoJSONReader(const geom::GeometryFactory& gf);
GeoJSONReader();
~GeoJSONReader() = default;
std::unique_ptr<geom::Geometry> read(const std::string& geoJsonText) const;
GeoJSONFeatureCollection readFeatures(const std::string& geoJsonText) const;
private:
const geom::GeometryFactory& geometryFactory;
std::unique_ptr<geom::Geometry> readFeatureForGeometry(const geos_nlohmann::json& j) const;
GeoJSONFeature readFeature(const geos_nlohmann::json& j) const;
std::map<std::string, GeoJSONValue> readProperties(const geos_nlohmann::json& p) const;
GeoJSONValue readProperty(const geos_nlohmann::json& p) const;
std::unique_ptr<geom::Geometry> readFeatureCollectionForGeometry(
const geos_nlohmann::json& j) const;
GeoJSONFeatureCollection readFeatureCollection(
const geos_nlohmann::json& j) const;
std::unique_ptr<geom::Geometry> readGeometry(
const geos_nlohmann::json& j) const;
std::unique_ptr<geom::Point> readPoint(const geos_nlohmann::json& j) const;
geom::Coordinate readCoordinate(const std::vector<double>& coords) const;
std::unique_ptr<geom::LineString> readLineString(
const geos_nlohmann::json& j) const;
std::unique_ptr<geom::Polygon> readPolygon(
const geos_nlohmann::json& j) const;
std::unique_ptr<geom::Polygon> readPolygon(
const std::vector<std::vector<std::vector<double>>>& c) const;
std::unique_ptr<geom::MultiPoint> readMultiPoint(
const geos_nlohmann::json& j) const;
std::unique_ptr<geom::MultiLineString> readMultiLineString(
const geos_nlohmann::json& j) const;
std::unique_ptr<geom::MultiPolygon> readMultiPolygon(
const geos_nlohmann::json& j) const;
std::unique_ptr<geom::GeometryCollection> readGeometryCollection(
const geos_nlohmann::json& j) const;
};
} // namespace io
} // namespace geos
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::GeometryCollection
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
geos::geom::LineString
Definition LineString.h:66
geos::geom::LinearRing
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
geos::geom::MultiLineString
Models a collection of LineStrings.
Definition MultiLineString.h:49
geos::geom::MultiPoint
Definition MultiPoint.h:50
geos::geom::MultiPolygon
Definition MultiPolygon.h:58
geos::geom::Point
Definition Point.h:61
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::geom::PrecisionModel
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
geos::io::GeoJSONReader::GeoJSONReader
GeoJSONReader(const geom::GeometryFactory &gf)
Initialize parser with given GeometryFactory.
geos::io::GeoJSONReader::GeoJSONReader
GeoJSONReader()
Initialize parser with default GeometryFactory.
geos::io::GeoJSONReader::read
std::unique_ptr< geom::Geometry > read(const std::string &geoJsonText) const
Parse a GeoJSON string returning a Geometry.
geos::geom
Definition Angle.h:26
geos::io
Contains the interfaces for converting JTS objects to and from other formats.
Definition Geometry.h:65
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38