Class GeoJSONWriter

Object
GeoJSONWriter
All Implemented Interfaces:
AutoCloseable

public class GeoJSONWriter extends Object implements AutoCloseable
Wrapper to handle writing GeoJSON FeatureCollections
Author:
ian
  • Field Details

    • DEFAULT_DATE_FORMAT

      public static final String DEFAULT_DATE_FORMAT
      Date format (ISO 8601)
      See Also:
    • DEFAULT_TIME_ZONE

      public static final TimeZone DEFAULT_TIME_ZONE
      Default time zone, GMT
    • DEFAULT_DATE_FORMATTER

      public static final FastDateFormat DEFAULT_DATE_FORMATTER
  • Constructor Details

    • GeoJSONWriter

      public GeoJSONWriter(OutputStream outputStream) throws IOException
      Prepares a writer over the target output stream.
      Parameters:
      outputStream -
      Throws:
      IOException
  • Method Details

    • write

      public void write(SimpleFeature currentFeature) throws IOException
      Writes a single feature onto the output.
      Parameters:
      currentFeature -
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException
    • isEncodeFeatureBounds

      public boolean isEncodeFeatureBounds()
      Returns:
      the encodeFeatureCollectionBounds
    • setEncodeFeatureBounds

      public void setEncodeFeatureBounds(boolean encodeFeatureCollectionBounds)
      Parameters:
      encodeFeatureCollectionBounds - the encodeFeatureCollectionBounds to set
    • toGeoJSON

      public static String toGeoJSON(Geometry geometry)
      Utility encoding a single JTS geometry in GeoJSON, and returning it as a string
    • toGeoJSON

      public static String toGeoJSON(Geometry geometry, int maxDecimals)
      Utility encoding a single JTS geometry in GeoJSON with configurable max decimals, and returning it as a string
    • toGeoJSON

      public static String toGeoJSON(SimpleFeature f)
      Utility encoding a single SimpleFeature, and returning it as a string
    • toGeoJSON

      public static String toGeoJSON(SimpleFeatureCollection fc)
      Utility encoding a @link SimpleFeatureCollection}, 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

      public void writeFeatureCollection(SimpleFeatureCollection features) throws IOException
      Encodes the whole feature collection onto the output
      Throws:
      IOException
    • setBounds

      public void setBounds(ReferencedEnvelope bbox)
    • 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

      public void setTimeZone(TimeZone tz)
      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

      public TimeZone getTimeZone(TimeZone tz)
      Returns the timezone used to format dates. Defaults to GMT.
    • setDatePattern

      public void setDatePattern(String pattern)
      Sets the date format for time encoding
      Parameters:
      pattern - SimpleDateFormat compatible * pattern
    • getDatePattern

      public String getDatePattern()
      Returns the date formatter pattern. Defaults to DEFAULT_DATE_FORMAT