Package org.locationtech.jts.io.geojson
Class GeoJsonReader
- java.lang.Object
-
- org.locationtech.jts.io.geojson.GeoJsonReader
-
public class GeoJsonReader extends java.lang.ObjectReads a GeoJson Geometry from a JSON fragment into aGeometry.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
PrecisionModelmatches 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 Modifier and Type Field Description private GeometryFactorygf
-
Constructor Summary
Constructors Constructor Description GeoJsonReader()The default constructor uses the SRID from the Geojson CRS and the defaultPrecisionModelto create aGeometryFactory.GeoJsonReader(GeometryFactory geometryFactory)This constructor accepts aGeometryFactorythat is used to create the output geometries and to override the GeoJson CRS.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Geometrycreate(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory)private CoordinateSequencecreateCoordinate(java.util.List<java.lang.Number> ordinates)private CoordinateSequencecreateCoordinateSequence(java.util.List<java.util.List<java.lang.Number>> coordinates)private GeometrycreateGeometryCollection(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory)private GeometrycreateLineString(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory)private GeometrycreateMultiLineString(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory)private GeometrycreateMultiPoint(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory)private GeometrycreateMultiPolygon(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory)private GeometrycreatePoint(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory)private GeometrycreatePolygon(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory)private GeometryFactorygetGeometryFactory(java.util.Map<java.lang.String,java.lang.Object> geometryMap)Geometryread(java.io.Reader reader)Reads a GeoJson Geometry from aReaderinto a singleGeometry.Geometryread(java.lang.String json)Reads a GeoJson Geometry from a String into a singleGeometry.
-
-
-
Field Detail
-
gf
private GeometryFactory gf
-
-
Constructor Detail
-
GeoJsonReader
public GeoJsonReader()
The default constructor uses the SRID from the Geojson CRS and the defaultPrecisionModelto 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
public GeoJsonReader(GeometryFactory geometryFactory)
This constructor accepts aGeometryFactorythat is used to create the output geometries and to override the GeoJson CRS.- Parameters:
geometryFactory- a GeometryFactory
-
-
Method Detail
-
read
public Geometry read(java.lang.String json) throws ParseException
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
public Geometry read(java.io.Reader reader) throws ParseException
Reads a GeoJson Geometry from aReaderinto a singleGeometry.- 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(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory) throws ParseException
- Throws:
ParseException
-
createGeometryCollection
private Geometry createGeometryCollection(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory) throws ParseException
- Throws:
ParseException
-
createMultiPolygon
private Geometry createMultiPolygon(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory) throws ParseException
- Throws:
ParseException
-
createMultiLineString
private Geometry createMultiLineString(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory) throws ParseException
- Throws:
ParseException
-
createMultiPoint
private Geometry createMultiPoint(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory) throws ParseException
- Throws:
ParseException
-
createPolygon
private Geometry createPolygon(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory) throws ParseException
- Throws:
ParseException
-
createLineString
private Geometry createLineString(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory) throws ParseException
- Throws:
ParseException
-
createPoint
private Geometry createPoint(java.util.Map<java.lang.String,java.lang.Object> geometryMap, GeometryFactory geometryFactory) throws ParseException
- Throws:
ParseException
-
getGeometryFactory
private GeometryFactory getGeometryFactory(java.util.Map<java.lang.String,java.lang.Object> geometryMap) throws ParseException
- Throws:
ParseException
-
createCoordinateSequence
private CoordinateSequence createCoordinateSequence(java.util.List<java.util.List<java.lang.Number>> coordinates)
-
createCoordinate
private CoordinateSequence createCoordinate(java.util.List<java.lang.Number> ordinates)
-
-