Package org.locationtech.jts.io.geojson
Class GeoJsonReader
java.lang.Object
org.locationtech.jts.io.geojson.GeoJsonReader
Reads a GeoJson Geometry from a JSON fragment into a
Geometry
.
A specification of the GeoJson format can be found at the GeoJson web site: http://geojson.org/geojson-spec.html.
It is the caller's responsibility to ensure that the supplied
PrecisionModel
matches the precision of the incoming data. If a lower
precision for the data is required, a subsequent process must be run on the
data to reduce its precision.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor uses the SRID from the Geojson CRS and the defaultPrecisionModel
to create aGeometryFactory
.GeoJsonReader
(GeometryFactory geometryFactory) This constructor accepts aGeometryFactory
that is used to create the output geometries and to override the GeoJson CRS. -
Method Summary
Modifier and TypeMethodDescriptionprivate Geometry
create
(Map<String, Object> geometryMap, GeometryFactory geometryFactory) private CoordinateSequence
createCoordinate
(List<Number> ordinates) private CoordinateSequence
createCoordinateSequence
(List<List<Number>> coordinates) private Geometry
createGeometryCollection
(Map<String, Object> geometryMap, GeometryFactory geometryFactory) private Geometry
createLineString
(Map<String, Object> geometryMap, GeometryFactory geometryFactory) private Geometry
createMultiLineString
(Map<String, Object> geometryMap, GeometryFactory geometryFactory) private Geometry
createMultiPoint
(Map<String, Object> geometryMap, GeometryFactory geometryFactory) private Geometry
createMultiPolygon
(Map<String, Object> geometryMap, GeometryFactory geometryFactory) private Geometry
createPoint
(Map<String, Object> geometryMap, GeometryFactory geometryFactory) private Geometry
createPolygon
(Map<String, Object> geometryMap, GeometryFactory geometryFactory) private GeometryFactory
getGeometryFactory
(Map<String, Object> geometryMap) Reads a GeoJson Geometry from a String into a singleGeometry
.
-
Field Details
-
gf
-
-
Constructor Details
-
GeoJsonReader
public GeoJsonReader()The default constructor uses the SRID from the Geojson CRS and the defaultPrecisionModel
to create aGeometryFactory
. If there is no CRS specified then the default CRS is a geographic coordinate reference system, using the WGS84 datum, and with longitude and latitude units of decimal degrees (SRID = 4326) -
GeoJsonReader
This constructor accepts aGeometryFactory
that is used to create the output geometries and to override the GeoJson CRS.- Parameters:
geometryFactory
- a GeometryFactory
-
-
Method Details
-
read
Reads a GeoJson Geometry from a String into a singleGeometry
.- Parameters:
json
- The GeoJson String to parse- Returns:
- the resulting JTS Geometry
- Throws:
ParseException
- throws a ParseException if the JSON string cannot be parsed
-
read
- Parameters:
reader
- The input source- Returns:
- The resulting JTS Geometry
- Throws:
ParseException
- throws a ParseException if the JSON string cannot be parsed
-
create
private Geometry create(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException- Throws:
ParseException
-
createGeometryCollection
private Geometry createGeometryCollection(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException- Throws:
ParseException
-
createMultiPolygon
private Geometry createMultiPolygon(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException- Throws:
ParseException
-
createMultiLineString
private Geometry createMultiLineString(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException- Throws:
ParseException
-
createMultiPoint
private Geometry createMultiPoint(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException- Throws:
ParseException
-
createPolygon
private Geometry createPolygon(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException- Throws:
ParseException
-
createLineString
private Geometry createLineString(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException- Throws:
ParseException
-
createPoint
private Geometry createPoint(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException- Throws:
ParseException
-
getGeometryFactory
- Throws:
ParseException
-
createCoordinateSequence
-
createCoordinate
-