Package org.geotools.data.geojson
Class GeoJSONReader
Object
GeoJSONReader
- All Implemented Interfaces:
AutoCloseable
Utility class to provide a reader for GeoJSON streams
- Author:
- ian
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBuilds 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
Modifier and TypeMethodDescriptionvoidclose()Parses and returns a single feature from the sourceParses all features in the source and returns them as an in-memory feature collection with a stableFeatureType.Get the Field Name to use for IDsGet the Prefix to use for IDsReturns the Strategy Used to Generate IDsReturns aFeatureIteratorstreaming over the provided source.protected PagingFeatureCollectiongetPagingFeatureCollection(SimpleFeatureCollection result, Integer matched, ObjectNode next) 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):booleanReturns true if the source is still connected, false otherwise.booleanReturns true if the parser is trying to convert string formatted as dates into java.util.Date, false otherwise.booleanstatic 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 Details
-
GEOMETRY_NAME
GEOMETRY_NAME- See Also:
-
TOP_LEVEL_ATTRIBUTES
Top Level Attributes Not Included in Properties
-
-
Constructor Details
-
GeoJSONReader
Builds a GeoJSON parser from a GeoJSON source, located at the specified URL.- Parameters:
url-- Throws:
IOException
-
GeoJSONReader
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
Builds a GeoJSON parser from a GeoJSON document, provided as anInputStream- Throws:
IOException
-
GeoJSONReader
Builds a GeoJSON parser from a GeoJSON document, provided as a string- Throws:
IOException
-
-
Method Details
-
getIdStrategy
Returns the Strategy Used to Generate IDs- Returns:
- the idStrategy
-
setIdStrategy
Sets the Strategy Used to Generate IDs- Parameters:
idStrategy- the idStrategy to set
-
getIdPrefix
Get the Prefix to use for IDs- Returns:
- the idPrefix
-
setIdPrefix
Set the Prefix to use for IDs- Parameters:
idPrefix- the idPrefix to set
-
getIdFieldName
Get the Field Name to use for IDs- Returns:
- the idFieldName
-
setIdFieldName
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
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
Parses and returns a feature collection from a GeoJSON -
parseGeometry
Parses and returns a single geometry -
getFeature
Parses and returns a single feature from the source- Throws:
IOException
-
getFeatures
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
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
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
- 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
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-