Class Feature

  • All Implemented Interfaces:
    GeoJson, java.io.Serializable

    public final class Feature
    extends java.lang.Object
    implements GeoJson
    This defines a GeoJson Feature object which represents a spatially bound thing. Every Feature object is a GeoJson object no matter where it occurs in a GeoJson text. A Feature object will always have a "TYPE" member with the value "Feature".

    A Feature object has a member with the name "geometry". The value of the geometry member SHALL be either a Geometry object or, in the case that the Feature is unlocated, a JSON null value.

    A Feature object has a member with the name "properties". The value of the properties member is an object (any JSON object or a JSON null value).

    If a Feature has a commonly used identifier, that identifier SHOULD be included as a member of the Feature object through the id() method, and the value of this member is either a JSON string or number.

    An example of a serialized feature is given below:

     {
       "TYPE": "Feature",
       "geometry": {
         "TYPE": "Point",
         "coordinates": [102.0, 0.5]
       },
       "properties": {
         "prop0": "value0"
       }
     
    Since:
    1.0.0
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addBooleanProperty​(java.lang.String key, java.lang.Boolean value)
      Convenience method to add a Boolean member.
      void addCharacterProperty​(java.lang.String key, java.lang.Character value)
      Convenience method to add a Character member.
      void addNumberProperty​(java.lang.String key, java.lang.Number value)
      Convenience method to add a Number member.
      void addProperty​(java.lang.String key, com.google.gson.JsonElement value)
      Convenience method to add a JsonElement member.
      void addStringProperty​(java.lang.String key, java.lang.String value)
      Convenience method to add a String member.
      BoundingBox bbox()
      A Feature Collection might have a member named bbox to include information on the coordinate range for it's Features.
      boolean equals​(java.lang.Object obj)  
      static Feature fromGeometry​(Geometry geometry)
      Create a new instance of this class by giving the feature a Geometry.
      static Feature fromGeometry​(Geometry geometry, com.google.gson.JsonObject properties)
      Create a new instance of this class by giving the feature a Geometry and optionally a set of properties.
      static Feature fromGeometry​(Geometry geometry, com.google.gson.JsonObject properties, BoundingBox bbox)
      Create a new instance of this class by giving the feature a Geometry, optionally a set of properties, and optionally pass in a bbox.
      static Feature fromGeometry​(Geometry geometry, com.google.gson.JsonObject properties, java.lang.String id)
      Create a new instance of this class by giving the feature a Geometry, optionally a set of properties, and a String which represents the objects id.
      static Feature fromGeometry​(Geometry geometry, com.google.gson.JsonObject properties, java.lang.String id, BoundingBox bbox)
      Create a new instance of this class by giving the feature a Geometry, optionally a set of properties, and a String which represents the objects id.
      static Feature fromGeometry​(Geometry geometry, BoundingBox bbox)
      Create a new instance of this class by giving the feature a Geometry.
      static Feature fromJson​(java.lang.String json)
      Create a new instance of this class by passing in a formatted valid JSON String.
      Geometry geometry()
      The geometry which makes up this feature.
      java.lang.Boolean getBooleanProperty​(java.lang.String key)
      Convenience method to get a Boolean member.
      java.lang.Character getCharacterProperty​(java.lang.String key)
      Deprecated.
      This method was passing the call to JsonElement::getAsCharacter() which is in turn deprecated because of misleading nature, as it does not get this element as a char but rather as a string's first character.
      java.lang.Number getNumberProperty​(java.lang.String key)
      Convenience method to get a Number member.
      com.google.gson.JsonElement getProperty​(java.lang.String key)
      Convenience method to get a JsonElement member.
      java.lang.String getStringProperty​(java.lang.String key)
      Convenience method to get a String member.
      int hashCode()  
      boolean hasNonNullValueForProperty​(java.lang.String key)
      Convenience method to check for a member by name as well as non-null value.
      boolean hasProperty​(java.lang.String key)
      Convenience method to check if a member with the specified name is present in this object.
      java.lang.String id()
      A feature may have a commonly used identifier which is either a unique String or number.
      com.google.gson.JsonObject properties()
      This contains the JSON object which holds the feature properties.
      com.google.gson.JsonElement removeProperty​(java.lang.String key)
      Removes the property from the object properties.
      java.lang.String toJson()
      This takes the currently defined values found inside this instance and converts it to a GeoJson string.
      java.lang.String toString()  
      java.lang.String type()
      This describes the TYPE of GeoJson geometry this object is, thus this will always return Feature.
      static com.google.gson.TypeAdapter<Feature> typeAdapter​(com.google.gson.Gson gson)
      Gson TYPE adapter for parsing Gson to this class.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • fromJson

        public static Feature fromJson​(@NonNull
                                       java.lang.String json)
        Create a new instance of this class by passing in a formatted valid JSON String. If you are creating a Feature object from scratch it is better to use one of the other provided static factory methods such as fromGeometry(Geometry).
        Parameters:
        json - a formatted valid JSON string defining a GeoJson Feature
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        1.0.0
      • fromGeometry

        public static Feature fromGeometry​(@Nullable
                                           Geometry geometry)
        Create a new instance of this class by giving the feature a Geometry.
        Parameters:
        geometry - a single geometry which makes up this feature object
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        1.0.0
      • fromGeometry

        public static Feature fromGeometry​(@Nullable
                                           Geometry geometry,
                                           @Nullable
                                           BoundingBox bbox)
        Create a new instance of this class by giving the feature a Geometry. You can also pass in a double array defining a bounding box.
        Parameters:
        geometry - a single geometry which makes up this feature object
        bbox - optionally include a bbox definition as a double array
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        1.0.0
      • fromGeometry

        public static Feature fromGeometry​(@Nullable
                                           Geometry geometry,
                                           @Nullable
                                           com.google.gson.JsonObject properties)
        Create a new instance of this class by giving the feature a Geometry and optionally a set of properties.
        Parameters:
        geometry - a single geometry which makes up this feature object
        properties - a JsonObject containing the feature properties
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        1.0.0
      • fromGeometry

        public static Feature fromGeometry​(@Nullable
                                           Geometry geometry,
                                           @Nullable
                                           com.google.gson.JsonObject properties,
                                           @Nullable
                                           BoundingBox bbox)
        Create a new instance of this class by giving the feature a Geometry, optionally a set of properties, and optionally pass in a bbox.
        Parameters:
        geometry - a single geometry which makes up this feature object
        bbox - optionally include a bbox definition as a double array
        properties - a JsonObject containing the feature properties
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        1.0.0
      • fromGeometry

        public static Feature fromGeometry​(@Nullable
                                           Geometry geometry,
                                           @Nullable
                                           com.google.gson.JsonObject properties,
                                           @Nullable
                                           java.lang.String id)
        Create a new instance of this class by giving the feature a Geometry, optionally a set of properties, and a String which represents the objects id.
        Parameters:
        geometry - a single geometry which makes up this feature object
        properties - a JsonObject containing the feature properties
        id - common identifier of this feature
        Returns:
        Feature
        Since:
        1.0.0
      • fromGeometry

        public static Feature fromGeometry​(@Nullable
                                           Geometry geometry,
                                           @Nullable
                                           com.google.gson.JsonObject properties,
                                           @Nullable
                                           java.lang.String id,
                                           @Nullable
                                           BoundingBox bbox)
        Create a new instance of this class by giving the feature a Geometry, optionally a set of properties, and a String which represents the objects id.
        Parameters:
        geometry - a single geometry which makes up this feature object
        properties - a JsonObject containing the feature properties
        bbox - optionally include a bbox definition as a double array
        id - common identifier of this feature
        Returns:
        Feature
        Since:
        1.0.0
      • type

        @NonNull
        public java.lang.String type()
        This describes the TYPE of GeoJson geometry this object is, thus this will always return Feature.
        Specified by:
        type in interface GeoJson
        Returns:
        a String which describes the TYPE of geometry, for this object it will always return Feature
        Since:
        1.0.0
      • bbox

        @Nullable
        public BoundingBox bbox()
        A Feature Collection might have a member named bbox to include information on the coordinate range for it's Features. The value of the bbox member MUST be a list of size 2*n where n is the number of dimensions represented in the contained feature geometries, with all axes of the most southwesterly point followed by all axes of the more northeasterly point. The axes order of a bbox follows the axes order of geometries.
        Specified by:
        bbox in interface GeoJson
        Returns:
        a list of double coordinate values describing a bounding box
        Since:
        3.0.0
      • id

        @Nullable
        public java.lang.String id()
        A feature may have a commonly used identifier which is either a unique String or number.
        Returns:
        a String containing this features unique identification or null if one wasn't given during creation.
        Since:
        1.0.0
      • geometry

        @Nullable
        public Geometry geometry()
        The geometry which makes up this feature. A Geometry object represents points, curves, and surfaces in coordinate space. One of the seven geometries provided inside this library can be passed in through one of the static factory methods.
        Returns:
        a single defined Geometry which makes this feature spatially aware
        Since:
        1.0.0
      • properties

        @NonNull
        public com.google.gson.JsonObject properties()
        This contains the JSON object which holds the feature properties. The value of the properties member is a JsonObject and might be empty if no properties are provided.
        Returns:
        a JsonObject which holds this features current properties
        Since:
        1.0.0
      • toJson

        public java.lang.String toJson()
        This takes the currently defined values found inside this instance and converts it to a GeoJson string.
        Specified by:
        toJson in interface GeoJson
        Returns:
        a JSON string which represents this Feature
        Since:
        1.0.0
      • typeAdapter

        public static com.google.gson.TypeAdapter<Feature> typeAdapter​(com.google.gson.Gson gson)
        Gson TYPE adapter for parsing Gson to this class.
        Parameters:
        gson - the built Gson object
        Returns:
        the TYPE adapter for this class
        Since:
        3.0.0
      • addStringProperty

        public void addStringProperty​(java.lang.String key,
                                      java.lang.String value)
        Convenience method to add a String member.
        Parameters:
        key - name of the member
        value - the String value associated with the member
        Since:
        1.0.0
      • addNumberProperty

        public void addNumberProperty​(java.lang.String key,
                                      java.lang.Number value)
        Convenience method to add a Number member.
        Parameters:
        key - name of the member
        value - the Number value associated with the member
        Since:
        1.0.0
      • addBooleanProperty

        public void addBooleanProperty​(java.lang.String key,
                                       java.lang.Boolean value)
        Convenience method to add a Boolean member.
        Parameters:
        key - name of the member
        value - the Boolean value associated with the member
        Since:
        1.0.0
      • addCharacterProperty

        public void addCharacterProperty​(java.lang.String key,
                                         java.lang.Character value)
        Convenience method to add a Character member.
        Parameters:
        key - name of the member
        value - the Character value associated with the member
        Since:
        1.0.0
      • addProperty

        public void addProperty​(java.lang.String key,
                                com.google.gson.JsonElement value)
        Convenience method to add a JsonElement member.
        Parameters:
        key - name of the member
        value - the JsonElement value associated with the member
        Since:
        1.0.0
      • getStringProperty

        public java.lang.String getStringProperty​(java.lang.String key)
        Convenience method to get a String member.
        Parameters:
        key - name of the member
        Returns:
        the value of the member, null if it doesn't exist
        Since:
        1.0.0
      • getNumberProperty

        public java.lang.Number getNumberProperty​(java.lang.String key)
        Convenience method to get a Number member.
        Parameters:
        key - name of the member
        Returns:
        the value of the member, null if it doesn't exist
        Since:
        1.0.0
      • getBooleanProperty

        public java.lang.Boolean getBooleanProperty​(java.lang.String key)
        Convenience method to get a Boolean member.
        Parameters:
        key - name of the member
        Returns:
        the value of the member, null if it doesn't exist
        Since:
        1.0.0
      • getCharacterProperty

        @Deprecated
        @Nullable
        public java.lang.Character getCharacterProperty​(java.lang.String key)
        Deprecated.
        This method was passing the call to JsonElement::getAsCharacter() which is in turn deprecated because of misleading nature, as it does not get this element as a char but rather as a string's first character.
        Convenience method to get a Character member.
        Parameters:
        key - name of the member
        Returns:
        the value of the member, null if it doesn't exist
        Since:
        1.0.0
      • getProperty

        public com.google.gson.JsonElement getProperty​(java.lang.String key)
        Convenience method to get a JsonElement member.
        Parameters:
        key - name of the member
        Returns:
        the value of the member, null if it doesn't exist
        Since:
        1.0.0
      • removeProperty

        public com.google.gson.JsonElement removeProperty​(java.lang.String key)
        Removes the property from the object properties.
        Parameters:
        key - name of the member
        Returns:
        Removed property from the key string passed in through the parameter.
        Since:
        1.0.0
      • hasProperty

        public boolean hasProperty​(java.lang.String key)
        Convenience method to check if a member with the specified name is present in this object.
        Parameters:
        key - name of the member
        Returns:
        true if there is the member has the specified name, false otherwise.
        Since:
        1.0.0
      • hasNonNullValueForProperty

        public boolean hasNonNullValueForProperty​(java.lang.String key)
        Convenience method to check for a member by name as well as non-null value.
        Parameters:
        key - name of the member
        Returns:
        true if member is present with non-null value, false otherwise.
        Since:
        1.3.0
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object