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 SummaryNested Classes Modifier and Type Class Description static classGeoJSONReader.IdStrategyID Strategy.
 - 
Field SummaryFields Modifier and Type Field Description static StringGEOMETRY_NAMEGEOMETRY_NAMEstatic ObjectTOP_LEVEL_ATTRIBUTESTop Level Attributes Not Included in Properties
 - 
Constructor SummaryConstructors 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 SummaryAll 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_NAMEpublic static final String GEOMETRY_NAME GEOMETRY_NAME- See Also:
- Constant Field Values
 
 - 
TOP_LEVEL_ATTRIBUTESpublic static final Object TOP_LEVEL_ATTRIBUTES Top Level Attributes Not Included in Properties
 
- 
 - 
Constructor Detail- 
GeoJSONReaderpublic GeoJSONReader(URL url) throws IOException Builds a GeoJSON parser from a GeoJSON source, located at the specified URL.- Parameters:
- url-
- Throws:
- IOException
 
 - 
GeoJSONReaderpublic 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
 
 - 
GeoJSONReaderpublic GeoJSONReader(InputStream is) throws IOException Builds a GeoJSON parser from a GeoJSON document, provided as anInputStream- Throws:
- IOException
 
 - 
GeoJSONReaderpublic GeoJSONReader(String json) throws IOException Builds a GeoJSON parser from a GeoJSON document, provided as a string- Throws:
- IOException
 
 
- 
 - 
Method Detail- 
getIdStrategypublic GeoJSONReader.IdStrategy getIdStrategy() Returns the Strategy Used to Generate IDs- Returns:
- the idStrategy
 
 - 
setIdStrategypublic void setIdStrategy(GeoJSONReader.IdStrategy idStrategy) Sets the Strategy Used to Generate IDs- Parameters:
- idStrategy- the idStrategy to set
 
 - 
getIdPrefixpublic String getIdPrefix() Get the Prefix to use for IDs- Returns:
- the idPrefix
 
 - 
setIdPrefixpublic void setIdPrefix(String idPrefix) Set the Prefix to use for IDs- Parameters:
- idPrefix- the idPrefix to set
 
 - 
getIdFieldNamepublic String getIdFieldName() Get the Field Name to use for IDs- Returns:
- the idFieldName
 
 - 
setIdFieldNamepublic void setIdFieldName(String idFieldName) Set the Field Name to use for IDs- Parameters:
- idFieldName- the idFieldName to set
 
 - 
isGuessingDatespublic boolean isGuessingDates() Returns true if the parser is trying to convert string formatted as dates into java.util.Date, false otherwise. Defaults to true.
 - 
setGuessingDatespublic void setGuessingDates(boolean guessingDates) Enables/Disables guessing strings formatted as dates into java.util.Date.
 - 
isConnectedpublic boolean isConnected() Returns true if the source is still connected, false otherwise.- Returns:
 
 - 
parseFeaturepublic static SimpleFeature parseFeature(String json) throws JsonParseException, IOException Pares and returns a single feature out of a GeoJSON document- Throws:
- JsonParseException
- IOException
 
 - 
parseFeaturepublic 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 parse
- idStrategy- Auto generated, prefixed or provided id
- idPrefix- Prefix for id
- idFieldName- Field name for existing id in json
- Returns:
- Simple Feature represenation of JSON
- Throws:
- JsonParseException- JSON Parsing Issue
- IOException- IO Exception reading json
 
 - 
parseFeatureCollectionpublic static SimpleFeatureCollection parseFeatureCollection(String jsonString) Parses and returns a feature collection from a GeoJSON
 - 
parseGeometrypublic static Geometry parseGeometry(String input) Parses and returns a single geometry
 - 
getFeaturepublic SimpleFeature getFeature() throws IOException Parses and returns a single feature from the source- Throws:
- IOException
 
 - 
getFeaturespublic 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
 
 - 
getPagingFeatureCollectionprotected PagingFeatureCollection getPagingFeatureCollection(SimpleFeatureCollection result, Integer matched, ObjectNode next) 
 - 
getIteratorpublic 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
 
 - 
getSchemapublic 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
 
 - 
setSchemapublic void setSchema(SimpleFeatureType schema) - Parameters:
- schema- the schema to set
 
 - 
isSchemaChangedpublic boolean isSchemaChanged() - Returns:
- the schemaChanged
 
 - 
setSchemaChangedpublic void setSchemaChanged(boolean schemaChanged) - Parameters:
- schemaChanged- the schemaChanged to set
 
 - 
closepublic void close() throws IOException- Specified by:
- closein interface- AutoCloseable
- Throws:
- IOException
 
 
- 
 
-