Class FeatureJSON
SimpleFeature feature = ...; FeatureJSON io = new FeatureJSON(); io.writeFeature(feature, "feature.json")); Iteratorfeatures = io.streamFeatureCollection("features.json"); while(features.hasNext()) { feature = features.next(); ... }
- Author:
- Justin Deoliveira, OpenGeo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
The flag controlling whether feature bounds are encoded.boolean
The flag controlling whether feature collection bounds are encoded.boolean
The flag controlling whether feature collection coordinate reference systems are encoded.boolean
The flag controlling whether feature coordinate reference systems are encoded.boolean
The flag controlling whether properties with null values are encoded.readCRS
(InputStream input) Reads a coordinate reference system from GeoJSON.Reads a coordinate reference system from GeoJSON.readFeature
(InputStream input) Reads a feature from GeoJSON.readFeature
(Object input) Reads a feature from GeoJSON.readFeatureCollection
(InputStream input) Reads a feature collection from GeoJSON.readFeatureCollection
(Object input) Reads a feature collection from GeoJSON.readFeatureCollectionSchema
(InputStream input, boolean nullValuesEncoded) Reads theSimpleFeatureType
of a GeoJSON feature collection.readFeatureCollectionSchema
(Object input, boolean nullValuesEncoded) Reads theSimpleFeatureType
of a GeoJSON feature collection.void
setEncodeFeatureBounds
(boolean encodeFeatureBounds) Sets the flag controlling whether feature bounds are encoded.void
setEncodeFeatureCollectionBounds
(boolean encodeFeatureCollectionBounds) Sets the flag controlling whether feature collection bounds are encoded.void
setEncodeFeatureCollectionCRS
(boolean encodeFeatureCollectionCRS) Sets the flag controlling whether feature collection coordinate reference systems are encoded.void
setEncodeFeatureCRS
(boolean encodeFeatureCRS) Sets the flag controlling whether feature coordinate reference systems are encoded.void
setEncodeNullValues
(boolean encodeNullValues) Sets the flag controlling whether properties with null values are encoded.void
setFeatureType
(SimpleFeatureType featureType) Sets the target feature type for parsing.streamFeatureCollection
(Object input) Reads a feature collection from GeoJSON streaming back the contents via an iterator.toString
(SimpleFeature feature) Writes a feature as GeoJSON returning the result as a string.Writes a coordinate reference system as GeoJSON returning the result as a string.toString
(FeatureCollection features) Writes a feature collection as GeoJSON returning the result as a string.void
writeCRS
(CoordinateReferenceSystem crs, OutputStream output) Writes a coordinate reference system as GeoJSON.void
writeCRS
(CoordinateReferenceSystem crs, Object output) Writes a coordinate reference system as GeoJSON.void
writeFeature
(SimpleFeature feature, OutputStream output) Writes a feature as GeoJSON.void
writeFeature
(SimpleFeature feature, Object output) Writes a feature as GeoJSON.void
writeFeatureCollection
(FeatureCollection features, OutputStream output) Writes a feature collection as GeoJSON.void
writeFeatureCollection
(FeatureCollection features, Object output) Writes a feature collection as GeoJSON.
-
Constructor Details
-
FeatureJSON
public FeatureJSON() -
FeatureJSON
-
-
Method Details
-
setFeatureType
Sets the target feature type for parsing.Setting the target feature type will help the geojson parser determine the type of feature properties during properties. When the type is not around all properties are returned as a string.
- Parameters:
featureType
- The feature type. Parsed features will reference this feature type.
-
setEncodeFeatureBounds
public void setEncodeFeatureBounds(boolean encodeFeatureBounds) Sets the flag controlling whether feature bounds are encoded.- See Also:
-
isEncodeFeatureBounds
public boolean isEncodeFeatureBounds()The flag controlling whether feature bounds are encoded.When set each feature object will contain a "bbox" attribute whose value is an array containing the elements of the bounding box (in x1,y1,x2,y2 order) of the feature
-
setEncodeFeatureCollectionBounds
public void setEncodeFeatureCollectionBounds(boolean encodeFeatureCollectionBounds) Sets the flag controlling whether feature collection bounds are encoded.- See Also:
-
isEncodeFeatureCollectionBounds
public boolean isEncodeFeatureCollectionBounds()The flag controlling whether feature collection bounds are encoded.When set the feature collection object will contain a "bbox" attribute whose value is an array containing elements of the bounding box (in x1,y1,x2,y2 order) of the feature collection.
-
setEncodeFeatureCRS
public void setEncodeFeatureCRS(boolean encodeFeatureCRS) Sets the flag controlling whether feature coordinate reference systems are encoded.- See Also:
-
isEncodeFeatureCRS
public boolean isEncodeFeatureCRS()The flag controlling whether feature coordinate reference systems are encoded.When set each feature object will contain a "crs" attribute describing the coordinate reference system of the feature.
-
setEncodeFeatureCollectionCRS
public void setEncodeFeatureCollectionCRS(boolean encodeFeatureCollectionCRS) Sets the flag controlling whether feature collection coordinate reference systems are encoded.- See Also:
-
isEncodeFeatureCollectionCRS
public boolean isEncodeFeatureCollectionCRS()The flag controlling whether feature collection coordinate reference systems are encoded.When set the feature collection object will contain a "crs" attribute describing the coordinate reference system of the feature collection.
-
setEncodeNullValues
public void setEncodeNullValues(boolean encodeNullValues) Sets the flag controlling whether properties with null values are encoded.- See Also:
-
isEncodeNullValues
public boolean isEncodeNullValues()The flag controlling whether properties with null values are encoded.When set, properties with null values are encoded as null in the GeoJSON document.
-
writeFeature
Writes a feature as GeoJSON.- Parameters:
feature
- The feature.output
- The output. SeeGeoJSONUtil.toWriter(Object)
for details.- Throws:
IOException
-
writeFeature
Writes a feature as GeoJSON.This method calls through to
#writeFeature(FeatureCollection, Object)
- Parameters:
feature
- The feature.output
- The output stream.- Throws:
IOException
-
toString
Writes a feature as GeoJSON returning the result as a string.- Parameters:
feature
- The feature- Returns:
- The geometry encoded as GeoJSON
- Throws:
IOException
-
readFeature
Reads a feature from GeoJSON.- Parameters:
input
- The input. SeeGeoJSONUtil.toReader(Object)
for details.- Returns:
- The feature.
- Throws:
IOException
- In the event of a parsing error or if the input json is invalid.
-
readFeature
Reads a feature from GeoJSON.This method calls through to
readFeature(Object)
- Parameters:
input
- The input stream.- Returns:
- The feature.
- Throws:
IOException
- In the event of a parsing error or if the input json is invalid.
-
writeFeatureCollection
Writes a feature collection as GeoJSON.- Parameters:
features
- The feature collection.output
- The output. SeeGeoJSONUtil.toWriter(Object)
for details.- Throws:
IOException
-
writeFeatureCollection
public void writeFeatureCollection(FeatureCollection features, OutputStream output) throws IOException Writes a feature collection as GeoJSON.This method calls through to
writeFeatureCollection(FeatureCollection, Object)
- Parameters:
features
- The feature collection.output
- The output strema to write to.- Throws:
IOException
-
readFeatureCollection
Reads a feature collection from GeoJSON.Warning that this method will load the entire feature collection into memory. For large feature collections
streamFeatureCollection(Object)
should be used.- Parameters:
input
- The input. SeeGeoJSONUtil.toReader(Object)
for details.- Returns:
- The feature collection.
- Throws:
IOException
- In the event of a parsing error or if the input json is invalid.
-
readFeatureCollection
Reads a feature collection from GeoJSON.Warning that this method will load the entire feature collection into memory. For large feature collections
streamFeatureCollection(Object)
should be used.This method calls through to
readFeatureCollection(Object)
.- Parameters:
input
- The input stream.- Returns:
- The feature collection.
- Throws:
IOException
- In the event of a parsing error or if the input json is invalid.
-
streamFeatureCollection
Reads a feature collection from GeoJSON streaming back the contents via an iterator.- Parameters:
input
- The input. SeeGeoJSONUtil.toReader(Object)
for details.- Returns:
- A feature iterator.
- Throws:
IOException
- In the event of a parsing error or if the input json is invalid.
-
toString
Writes a feature collection as GeoJSON returning the result as a string.- Parameters:
features
- The feature collection.- Returns:
- The feature collection encoded as GeoJSON
- Throws:
IOException
-
writeCRS
Writes a coordinate reference system as GeoJSON.- Parameters:
crs
- The coordinate reference system.output
- The output. SeeGeoJSONUtil.toWriter(Object)
for details.- Throws:
IOException
-
writeCRS
Writes a coordinate reference system as GeoJSON.This method calls through to
writeCRS(CoordinateReferenceSystem, Object)
- Parameters:
crs
- The coordinate reference system.output
- The output stream.- Throws:
IOException
-
readCRS
Reads a coordinate reference system from GeoJSON.This method only handles named coordinate reference system objects.
- Parameters:
input
- The input. SeeGeoJSONUtil.toReader(Object)
for details.- Returns:
- The coordinate reference system.
- Throws:
IOException
- In the event of a parsing error or if the input json is invalid.
-
readCRS
Reads a coordinate reference system from GeoJSON.This method only handles named coordinate reference system objects.
This method calls through to
readCRS(Object)
- Parameters:
input
- The input. SeeGeoJSONUtil.toReader(Object)
for details.- Returns:
- The coordinate reference system.
- Throws:
IOException
- In the event of a parsing error or if the input json is invalid.
-
readFeatureCollectionSchema
public SimpleFeatureType readFeatureCollectionSchema(Object input, boolean nullValuesEncoded) throws IOException Reads theSimpleFeatureType
of a GeoJSON feature collection. In the worst case, it will parse all features searching for attributes not present in previous features.- Parameters:
input
- The input. SeeGeoJSONUtil.toReader(Object)
for details.nullValuesEncoded
- if the input has null values encoded. If this flag is set to true and the GeoJSON doesn't actually encode null values, only the first feature attributes will be discovered.- Returns:
- The feature collection schema
- Throws:
IOException
- In the event of a parsing error or if the input json is invalid.
-
readFeatureCollectionSchema
public SimpleFeatureType readFeatureCollectionSchema(InputStream input, boolean nullValuesEncoded) throws IOException Reads theSimpleFeatureType
of a GeoJSON feature collection. In the worst case, it will parse all features searching for attributes not present in previous features.- Parameters:
input
- The input. SeeGeoJSONUtil.toReader(Object)
for details.nullValuesEncoded
- if the input has null values encoded. If this flag is set to true and the GeoJSON doesn't actually encode null values, only the first feature attributes will be discovered.- Returns:
- The feature collection schema
- Throws:
IOException
- In the event of a parsing error or if the input json is invalid.
-
toString
Writes a coordinate reference system as GeoJSON returning the result as a string.- Parameters:
crs
- The coordinate reference system.- Returns:
- The coordinate reference system encoded as GeoJSON
- Throws:
IOException
-