Package org.locationtech.spatial4j.io
Class GeoJSONReader
- java.lang.Object
-
- org.locationtech.spatial4j.io.GeoJSONReader
-
- All Implemented Interfaces:
ShapeIO,ShapeReader
public class GeoJSONReader extends Object implements ShapeReader
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringBUFFERprotected static StringBUFFER_UNITSprotected SpatialContextctxprotected ShapeFactoryshapeFactory
-
Constructor Summary
Constructors Constructor Description GeoJSONReader(SpatialContext ctx, SpatialContextFactory factory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetFormatName()Shaperead(Reader reader)Read aShapefrom the reader.Shaperead(Object value)protected CirclereadCircle(JSONParser parser)protected voidreadCoordListXYZ(JSONParser parser, ShapeFactory.PointsBuilder pointsBuilder)protected voidreadCoordXYZ(JSONParser parser, ShapeFactory.PointsBuilder pointsBuilder)protected doublereadDistance(String distProperty, String distUnitsProperty, JSONParser parser)Helper method to read a up until a distance value (radius, buffer) and it's corresponding unit are found.ShapereadIfSupported(Object value)protected ShapereadLineString(JSONParser parser)protected ShapereadMultiLineString(JSONParser parser)protected ShapereadMultiPoint(JSONParser parser)protected ShapereadMultiPolygon(JSONParser parser)protected ShapereadPoint(JSONParser parser)protected ShapeFactory.PolygonBuilderreadPolygon(JSONParser parser, ShapeFactory.PolygonBuilder polygonBuilder)protected ShapereadShape(JSONParser parser)protected ShapereadShapeFromCoordinates(String type, JSONParser parser)protected voidreadUntilEvent(JSONParser parser, int event)
-
-
-
Field Detail
-
BUFFER
protected static final String BUFFER
- See Also:
- Constant Field Values
-
BUFFER_UNITS
protected static final String BUFFER_UNITS
- See Also:
- Constant Field Values
-
ctx
protected final SpatialContext ctx
-
shapeFactory
protected final ShapeFactory shapeFactory
-
-
Constructor Detail
-
GeoJSONReader
public GeoJSONReader(SpatialContext ctx, SpatialContextFactory factory)
-
-
Method Detail
-
getFormatName
public String getFormatName()
- Specified by:
getFormatNamein interfaceShapeIO- Returns:
- the format name
-
read
public final Shape read(Reader reader) throws IOException, ParseException
Description copied from interface:ShapeReaderRead aShapefrom the reader.- Specified by:
readin interfaceShapeReader- Parameters:
reader- -- the input. Note, it will not be closed by this function- Returns:
- a valid Shape (never null)
- Throws:
IOExceptionParseException
-
read
public Shape read(Object value) throws IOException, ParseException, InvalidShapeException
- Specified by:
readin interfaceShapeReader- Parameters:
value- -- the input value, could be a String or other object- Returns:
- a shape valid shape (not null)
- Throws:
IOExceptionParseExceptionInvalidShapeException
-
readIfSupported
public Shape readIfSupported(Object value) throws InvalidShapeException
- Specified by:
readIfSupportedin interfaceShapeReader- Parameters:
value- -- the input value, could be a String or other object- Returns:
- a shape or null, if the input was un readable.
This will throw
InvalidShapeExceptionwhen we could read a shape, but it was invalid - Throws:
InvalidShapeException
-
readCoordXYZ
protected void readCoordXYZ(JSONParser parser, ShapeFactory.PointsBuilder pointsBuilder) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readCoordListXYZ
protected void readCoordListXYZ(JSONParser parser, ShapeFactory.PointsBuilder pointsBuilder) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readUntilEvent
protected void readUntilEvent(JSONParser parser, int event) throws IOException
- Throws:
IOException
-
readPoint
protected Shape readPoint(JSONParser parser) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readLineString
protected Shape readLineString(JSONParser parser) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readCircle
protected Circle readCircle(JSONParser parser) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readDistance
protected double readDistance(String distProperty, String distUnitsProperty, JSONParser parser) throws IOException
Helper method to read a up until a distance value (radius, buffer) and it's corresponding unit are found.This method returns 0 if no distance value is found. This method currently only handles distance units of "km".
- Parameters:
distProperty- The name of the property containing the distance value.distUnitsProperty- The name of the property containing the distance unit.- Throws:
IOException
-
readShape
protected Shape readShape(JSONParser parser) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readShapeFromCoordinates
protected Shape readShapeFromCoordinates(String type, JSONParser parser) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readPolygon
protected ShapeFactory.PolygonBuilder readPolygon(JSONParser parser, ShapeFactory.PolygonBuilder polygonBuilder) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readMultiPoint
protected Shape readMultiPoint(JSONParser parser) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readMultiLineString
protected Shape readMultiLineString(JSONParser parser) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
readMultiPolygon
protected Shape readMultiPolygon(JSONParser parser) throws IOException, ParseException
- Throws:
IOExceptionParseException
-
-