Package org.geotools.data.geojson
Class GeoJSONReader
- Object
-
- GeoJSONReader
-
- All Implemented Interfaces:
AutoCloseable
public class GeoJSONReader extends Object implements AutoCloseable
Utility class to provide a reader for GeoJSON streams- Author:
- ian
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGeoJSONReader.IdStrategyID Strategy.
-
Field Summary
Fields Modifier and Type Field Description static StringGEOMETRY_NAMEGEOMETRY_NAMEstatic ObjectTOP_LEVEL_ATTRIBUTESTop Level Attributes Not Included in Properties
-
Constructor Summary
Constructors Constructor Description GeoJSONReader(InputStream is)Builds a GeoJSON parser from a GeoJSON document, provided as anInputStreamGeoJSONReader(String json)Builds a GeoJSON parser from a GeoJSON document, provided as a stringGeoJSONReader(URL url)Builds a GeoJSON parser from a GeoJSON source, located at the specified URL.GeoJSONReader(URL url, GeoJSONReader.IdStrategy idStrategy)Builds a GeoJSON parser from a GeoJSON source, located at the specified URL.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()SimpleFeaturegetFeature()Parses and returns a single feature from the sourceSimpleFeatureCollectiongetFeatures()Parses all features in the source and returns them as an in-memory feature collection with a stableFeatureType.StringgetIdFieldName()Get the Field Name to use for IDsStringgetIdPrefix()Get the Prefix to use for IDsGeoJSONReader.IdStrategygetIdStrategy()Returns the Strategy Used to Generate IDsSimpleFeatureIteratorgetIterator()Returns aFeatureIteratorstreaming over the provided source.protected PagingFeatureCollectiongetPagingFeatureCollection(SimpleFeatureCollection result, Integer matched, ObjectNode next)FeatureTypegetSchema()Returns the current feature type, with the structure discovered so far while parsing features (parse them all in order to get a final, stable feature type):booleanisConnected()Returns true if the source is still connected, false otherwise.booleanisGuessingDates()Returns true if the parser is trying to convert string formatted as dates into java.util.Date, false otherwise.booleanisSchemaChanged()static SimpleFeatureparseFeature(String json)Pares and returns a single feature out of a GeoJSON documentstatic SimpleFeatureparseFeature(String json, GeoJSONReader.IdStrategy idStrategy, String idPrefix, String idFieldName)Parses and returns a single feature out of a GeoJSON document with id generation strategiesstatic SimpleFeatureCollectionparseFeatureCollection(String jsonString)Parses and returns a feature collection from a GeoJSONstatic GeometryparseGeometry(String input)Parses and returns a single geometryvoidsetGuessingDates(boolean guessingDates)Enables/Disables guessing strings formatted as dates into java.util.Date.voidsetIdFieldName(String idFieldName)Set the Field Name to use for IDsvoidsetIdPrefix(String idPrefix)Set the Prefix to use for IDsvoidsetIdStrategy(GeoJSONReader.IdStrategy idStrategy)Sets the Strategy Used to Generate IDsvoidsetSchema(SimpleFeatureType schema)voidsetSchemaChanged(boolean schemaChanged)
-
-
-
Field Detail
-
GEOMETRY_NAME
public static final String GEOMETRY_NAME
GEOMETRY_NAME- See Also:
- Constant Field Values
-
TOP_LEVEL_ATTRIBUTES
public static final Object TOP_LEVEL_ATTRIBUTES
Top Level Attributes Not Included in Properties
-
-
Constructor Detail
-
GeoJSONReader
public GeoJSONReader(URL url) throws IOException
Builds a GeoJSON parser from a GeoJSON source, located at the specified URL.- Parameters:
url-- Throws:
IOException
-
GeoJSONReader
public GeoJSONReader(URL url, GeoJSONReader.IdStrategy idStrategy) throws IOException
Builds a GeoJSON parser from a GeoJSON source, located at the specified URL.- Parameters:
url-idStrategy- the strategy to use for generating IDs. AUTO is autogenerated using basename and incremented integer. PREFIX uses a provided ID and prefix string. PROVIDED uses a provided ID without a prefix.- Throws:
IOException
-
GeoJSONReader
public GeoJSONReader(InputStream is) throws IOException
Builds a GeoJSON parser from a GeoJSON document, provided as anInputStream- Throws:
IOException
-
GeoJSONReader
public GeoJSONReader(String json) throws IOException
Builds a GeoJSON parser from a GeoJSON document, provided as a string- Throws:
IOException
-
-
Method Detail
-
getIdStrategy
public GeoJSONReader.IdStrategy getIdStrategy()
Returns the Strategy Used to Generate IDs- Returns:
- the idStrategy
-
setIdStrategy
public void setIdStrategy(GeoJSONReader.IdStrategy idStrategy)
Sets the Strategy Used to Generate IDs- Parameters:
idStrategy- the idStrategy to set
-
getIdPrefix
public String getIdPrefix()
Get the Prefix to use for IDs- Returns:
- the idPrefix
-
setIdPrefix
public void setIdPrefix(String idPrefix)
Set the Prefix to use for IDs- Parameters:
idPrefix- the idPrefix to set
-
getIdFieldName
public String getIdFieldName()
Get the Field Name to use for IDs- Returns:
- the idFieldName
-
setIdFieldName
public void setIdFieldName(String idFieldName)
Set the Field Name to use for IDs- Parameters:
idFieldName- the idFieldName to set
-
isGuessingDates
public boolean isGuessingDates()
Returns true if the parser is trying to convert string formatted as dates into java.util.Date, false otherwise. Defaults to true.
-
setGuessingDates
public void setGuessingDates(boolean guessingDates)
Enables/Disables guessing strings formatted as dates into java.util.Date.
-
isConnected
public boolean isConnected()
Returns true if the source is still connected, false otherwise.- Returns:
-
parseFeature
public static SimpleFeature parseFeature(String json) throws JsonParseException, IOException
Pares and returns a single feature out of a GeoJSON document- Throws:
JsonParseExceptionIOException
-
parseFeature
public static SimpleFeature parseFeature(String json, GeoJSONReader.IdStrategy idStrategy, String idPrefix, String idFieldName) throws JsonParseException, IOException
Parses and returns a single feature out of a GeoJSON document with id generation strategies- Parameters:
json- json to parseidStrategy- Auto generated, prefixed or provided ididPrefix- Prefix for ididFieldName- Field name for existing id in json- Returns:
- Simple Feature represenation of JSON
- Throws:
JsonParseException- JSON Parsing IssueIOException- IO Exception reading json
-
parseFeatureCollection
public static SimpleFeatureCollection parseFeatureCollection(String jsonString)
Parses and returns a feature collection from a GeoJSON
-
parseGeometry
public static Geometry parseGeometry(String input)
Parses and returns a single geometry
-
getFeature
public SimpleFeature getFeature() throws IOException
Parses and returns a single feature from the source- Throws:
IOException
-
getFeatures
public SimpleFeatureCollection getFeatures() throws IOException
Parses all features in the source and returns them as an in-memory feature collection with a stableFeatureType. In order to stream usegetIterator()instead.- Returns:
- Throws:
IOException
-
getPagingFeatureCollection
protected PagingFeatureCollection getPagingFeatureCollection(SimpleFeatureCollection result, Integer matched, ObjectNode next)
-
getIterator
public SimpleFeatureIterator getIterator() throws IOException
Returns aFeatureIteratorstreaming over the provided source. The feature type may evolve feature by feature, discovering new attributes that were not previosly encountered.- Returns:
- Throws:
IOException
-
getSchema
public FeatureType getSchema() throws IOException
Returns the current feature type, with the structure discovered so far while parsing features (parse them all in order to get a final, stable feature type):- Returns:
- Throws:
IOException
-
setSchema
public void setSchema(SimpleFeatureType schema)
- Parameters:
schema- the schema to set
-
isSchemaChanged
public boolean isSchemaChanged()
- Returns:
- the schemaChanged
-
setSchemaChanged
public void setSchemaChanged(boolean schemaChanged)
- Parameters:
schemaChanged- the schemaChanged to set
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
-