Class GeoJSONWriter

  • All Implemented Interfaces:
    AutoCloseable

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

      • 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 Detail

      • GeoJSONWriter

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

      • 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
      • 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
      • 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