Class GeoJSONReader

  • All Implemented Interfaces:
    AutoCloseable

    public class GeoJSONReader
    extends Object
    implements AutoCloseable
    Utility class to provide a reader for GeoJSON streams
    Author:
    ian
    • Field Detail

      • TOP_LEVEL_ATTRIBUTES

        public static final Object TOP_LEVEL_ATTRIBUTES
        Top Level Attributes Not Included in Properties
    • Constructor Detail

      • GeoJSONReader

        public GeoJSONReader​(URL url)
                      throws IOException
        Builds a GeoJSON parser from a GeoJSON source, located at the specified URL.
        Parameters:
        url -
        Throws:
        IOException
      • GeoJSONReader

        public GeoJSONReader​(URL url,
                             GeoJSONReader.IdStrategy idStrategy)
                      throws IOException
        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

        public GeoJSONReader​(String json)
                      throws IOException
        Builds a GeoJSON parser from a GeoJSON document, provided as a string
        Throws:
        IOException
    • Method Detail

      • getIdStrategy

        public GeoJSONReader.IdStrategy getIdStrategy()
        Returns the Strategy Used to Generate IDs
        Returns:
        the idStrategy
      • setIdStrategy

        public void setIdStrategy​(GeoJSONReader.IdStrategy idStrategy)
        Sets the Strategy Used to Generate IDs
        Parameters:
        idStrategy - the idStrategy to set
      • getIdPrefix

        public String getIdPrefix()
        Get the Prefix to use for IDs
        Returns:
        the idPrefix
      • setIdPrefix

        public void setIdPrefix​(String idPrefix)
        Set the Prefix to use for IDs
        Parameters:
        idPrefix - the idPrefix to set
      • getIdFieldName

        public String getIdFieldName()
        Get the Field Name to use for IDs
        Returns:
        the idFieldName
      • setIdFieldName

        public void setIdFieldName​(String idFieldName)
        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

        public static SimpleFeature parseFeature​(String json)
                                          throws JsonParseException,
                                                 IOException
        Pares and returns a single feature out of a GeoJSON document
        Throws:
        JsonParseException
        IOException
      • 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 parse
        idStrategy - Auto generated, prefixed or provided id
        idPrefix - Prefix for id
        idFieldName - Field name for existing id in json
        Returns:
        Simple Feature represenation of JSON
        Throws:
        JsonParseException - JSON Parsing Issue
        IOException - IO Exception reading json
      • parseFeatureCollection

        public static SimpleFeatureCollection parseFeatureCollection​(String jsonString)
        Parses and returns a feature collection from a GeoJSON
      • parseGeometry

        public static Geometry parseGeometry​(String input)
        Parses and returns a single geometry
      • getSchema

        public FeatureType getSchema()
                              throws IOException
        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

        public void setSchema​(SimpleFeatureType schema)
        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