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 class
GeoJSONReader.IdStrategy
ID Strategy.
-
Field Summary
Fields Modifier and Type Field Description static String
GEOMETRY_NAME
GEOMETRY_NAMEstatic Object
TOP_LEVEL_ATTRIBUTES
Top Level Attributes Not Included in Properties
-
Constructor Summary
Constructors Constructor Description GeoJSONReader(InputStream is)
Builds a GeoJSON parser from a GeoJSON document, provided as anInputStream
GeoJSONReader(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 void
close()
SimpleFeature
getFeature()
Parses and returns a single feature from the sourceSimpleFeatureCollection
getFeatures()
Parses all features in the source and returns them as an in-memory feature collection with a stableFeatureType
.String
getIdFieldName()
Get the Field Name to use for IDsString
getIdPrefix()
Get the Prefix to use for IDsGeoJSONReader.IdStrategy
getIdStrategy()
Returns the Strategy Used to Generate IDsSimpleFeatureIterator
getIterator()
Returns aFeatureIterator
streaming over the provided source.protected PagingFeatureCollection
getPagingFeatureCollection(SimpleFeatureCollection result, Integer matched, ObjectNode next)
FeatureType
getSchema()
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):boolean
isConnected()
Returns true if the source is still connected, false otherwise.boolean
isGuessingDates()
Returns true if the parser is trying to convert string formatted as dates into java.util.Date, false otherwise.boolean
isSchemaChanged()
static SimpleFeature
parseFeature(String json)
Pares and returns a single feature out of a GeoJSON documentstatic SimpleFeature
parseFeature(String json, GeoJSONReader.IdStrategy idStrategy, String idPrefix, String idFieldName)
Parses and returns a single feature out of a GeoJSON document with id generation strategiesstatic SimpleFeatureCollection
parseFeatureCollection(String jsonString)
Parses and returns a feature collection from a GeoJSONstatic Geometry
parseGeometry(String input)
Parses and returns a single geometryvoid
setGuessingDates(boolean guessingDates)
Enables/Disables guessing strings formatted as dates into java.util.Date.void
setIdFieldName(String idFieldName)
Set the Field Name to use for IDsvoid
setIdPrefix(String idPrefix)
Set the Prefix to use for IDsvoid
setIdStrategy(GeoJSONReader.IdStrategy idStrategy)
Sets the Strategy Used to Generate IDsvoid
setSchema(SimpleFeatureType schema)
void
setSchemaChanged(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:
JsonParseException
IOException
-
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 aFeatureIterator
streaming 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:
close
in interfaceAutoCloseable
- Throws:
IOException
-
-