Package org.geotools.data.geojson
Class GeoJSONWriter
Object
GeoJSONWriter
- All Implemented Interfaces:
AutoCloseable
Wrapper to handle writing GeoJSON FeatureCollections
- Author:
- ian
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGeoJSONWriter
(OutputStream outputStream) Prepares a writer over the target output stream. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Returns the date formatter pattern.int
Returns the max number of decimals used for encodinggetTimeZone
(TimeZone tz) Returns the timezone used to format dates.boolean
boolean
boolean
Returns true if pretty printing is enabled, false otherwise.boolean
Returns true if the generated JSON is for a single feature, without a feature collection wrapper around it.void
setBounds
(ReferencedEnvelope bbox) void
setDatePattern
(String pattern) Sets the date format for time encodingvoid
setEncodeFeatureBounds
(boolean encodeFeatureCollectionBounds) void
setEncodeFeatureCollectionCRS
(boolean b) Set to true to encode the feature collection CRS field.void
setMaxDecimals
(int number) Set how many decimals should be used in writing out the coordinates.void
setPrettyPrinting
(boolean prettyPrint) Enables/disables pretty printing.void
setSingleFeature
(boolean singleFeature) Turns on and off the single feature mode.void
setTimeZone
(TimeZone tz) Sets the Timezone used to format the date fields.static String
Utility encoding a singleSimpleFeature
, and returning it as a stringstatic String
Utility encoding a @linkSimpleFeatureCollection
}, and returning it as a stringstatic String
Utility encoding a single JTS geometry in GeoJSON, and returning it as a stringstatic String
Utility encoding a single JTS geometry in GeoJSON with configurable max decimals, and returning it as a stringvoid
write
(SimpleFeature currentFeature) Writes a single feature onto the output.void
Encodes the whole feature collection onto the output
-
Field Details
-
DEFAULT_DATE_FORMAT
Date format (ISO 8601)- See Also:
-
DEFAULT_TIME_ZONE
Default time zone, GMT -
DEFAULT_DATE_FORMATTER
public static final FastDateFormat DEFAULT_DATE_FORMATTER
-
-
Constructor Details
-
GeoJSONWriter
Prepares a writer over the target output stream.- Parameters:
outputStream
-- Throws:
IOException
-
-
Method Details
-
write
Writes a single feature onto the output.- Parameters:
currentFeature
-- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-
isEncodeFeatureBounds
public boolean isEncodeFeatureBounds()- Returns:
- the encodeFeatureCollectionBounds
-
setEncodeFeatureBounds
public void setEncodeFeatureBounds(boolean encodeFeatureCollectionBounds) - Parameters:
encodeFeatureCollectionBounds
- the encodeFeatureCollectionBounds to set
-
toGeoJSON
Utility encoding a single JTS geometry in GeoJSON, and returning it as a string -
toGeoJSON
Utility encoding a single JTS geometry in GeoJSON with configurable max decimals, and returning it as a string -
toGeoJSON
Utility encoding a singleSimpleFeature
, and returning it as a string -
toGeoJSON
Utility encoding a @linkSimpleFeatureCollection
}, and returning it as a string -
setEncodeFeatureCollectionCRS
public void setEncodeFeatureCollectionCRS(boolean b) Set to true to encode the feature collection CRS field. Defaults to false. -
isEncodeFeatureCollectionCRS
public boolean isEncodeFeatureCollectionCRS()- Returns:
- true if the feature collections CRS will be encoded in the output
-
getMaxDecimals
public int getMaxDecimals()Returns the max number of decimals used for encoding- Returns:
-
setMaxDecimals
public void setMaxDecimals(int number) Set how many decimals should be used in writing out the coordinates. Users should consult https://xkcd.com/2170/ before changing this value, unless they are using a CRS different from 4326.- Parameters:
number
- - the number of digits after the decimal place marker
-
writeFeatureCollection
Encodes the whole feature collection onto the output- Throws:
IOException
-
setBounds
-
isSingleFeature
public boolean isSingleFeature()Returns true if the generated JSON is for a single feature, without a feature collection wrapper around it. -
setSingleFeature
public void setSingleFeature(boolean singleFeature) Turns on and off the single feature mode. In single feature mode the feature collection wrapper elements won't be emitted. Defaults to false.- Parameters:
singleFeature
-
-
setPrettyPrinting
public void setPrettyPrinting(boolean prettyPrint) Enables/disables pretty printing. -
isPrettyPrinting
public boolean isPrettyPrinting()Returns true if pretty printing is enabled, false otherwise. -
setTimeZone
Sets the Timezone used to format the date fields.null
is a valid value, the JVM local timezone will be used in that case. -
getTimeZone
Returns the timezone used to format dates. Defaults to GMT. -
setDatePattern
Sets the date format for time encoding- Parameters:
pattern
-SimpleDateFormat
compatible * pattern
-
getDatePattern
Returns the date formatter pattern. Defaults to DEFAULT_DATE_FORMAT
-