Package com.mapbox.geojson
Class Feature
- java.lang.Object
-
- com.mapbox.geojson.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 voidaddBooleanProperty(java.lang.String key, java.lang.Boolean value)Convenience method to add a Boolean member.voidaddCharacterProperty(java.lang.String key, java.lang.Character value)Convenience method to add a Character member.voidaddNumberProperty(java.lang.String key, java.lang.Number value)Convenience method to add a Number member.voidaddProperty(java.lang.String key, com.google.gson.JsonElement value)Convenience method to add a JsonElement member.voidaddStringProperty(java.lang.String key, java.lang.String value)Convenience method to add a String member.BoundingBoxbbox()A Feature Collection might have a member namedbboxto include information on the coordinate range for it'sFeatures.booleanequals(java.lang.Object obj)static FeaturefromGeometry(Geometry geometry)Create a new instance of this class by giving the feature aGeometry.static FeaturefromGeometry(Geometry geometry, com.google.gson.JsonObject properties)Create a new instance of this class by giving the feature aGeometryand optionally a set of properties.static FeaturefromGeometry(Geometry geometry, com.google.gson.JsonObject properties, BoundingBox bbox)Create a new instance of this class by giving the feature aGeometry, optionally a set of properties, and optionally pass in a bbox.static FeaturefromGeometry(Geometry geometry, com.google.gson.JsonObject properties, java.lang.String id)Create a new instance of this class by giving the feature aGeometry, optionally a set of properties, and a String which represents the objects id.static FeaturefromGeometry(Geometry geometry, com.google.gson.JsonObject properties, java.lang.String id, BoundingBox bbox)Create a new instance of this class by giving the feature aGeometry, optionally a set of properties, and a String which represents the objects id.static FeaturefromGeometry(Geometry geometry, BoundingBox bbox)Create a new instance of this class by giving the feature aGeometry.static FeaturefromJson(java.lang.String json)Create a new instance of this class by passing in a formatted valid JSON String.Geometrygeometry()The geometry which makes up this feature.java.lang.BooleangetBooleanProperty(java.lang.String key)Convenience method to get a Boolean member.java.lang.CharactergetCharacterProperty(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.NumbergetNumberProperty(java.lang.String key)Convenience method to get a Number member.com.google.gson.JsonElementgetProperty(java.lang.String key)Convenience method to get a JsonElement member.java.lang.StringgetStringProperty(java.lang.String key)Convenience method to get a String member.inthashCode()booleanhasNonNullValueForProperty(java.lang.String key)Convenience method to check for a member by name as well as non-null value.booleanhasProperty(java.lang.String key)Convenience method to check if a member with the specified name is present in this object.java.lang.Stringid()A feature may have a commonly used identifier which is either a unique String or number.com.google.gson.JsonObjectproperties()This contains the JSON object which holds the feature properties.com.google.gson.JsonElementremoveProperty(java.lang.String key)Removes the property from the object properties.java.lang.StringtoJson()This takes the currently defined values found inside this instance and converts it to a GeoJson string.java.lang.StringtoString()java.lang.Stringtype()This describes the TYPE of GeoJson geometry this object is, thus this will always returnFeature.static com.google.gson.TypeAdapter<Feature>typeAdapter(com.google.gson.Gson gson)Gson TYPE adapter for parsing Gson to this class.
-
-
-
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 asfromGeometry(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 aGeometry.- 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 aGeometry. You can also pass in a double array defining a bounding box.- Parameters:
geometry- a single geometry which makes up this feature objectbbox- 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 aGeometryand optionally a set of properties.- Parameters:
geometry- a single geometry which makes up this feature objectproperties- aJsonObjectcontaining 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 aGeometry, optionally a set of properties, and optionally pass in a bbox.- Parameters:
geometry- a single geometry which makes up this feature objectbbox- optionally include a bbox definition as a double arrayproperties- aJsonObjectcontaining 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 aGeometry, optionally a set of properties, and a String which represents the objects id.- Parameters:
geometry- a single geometry which makes up this feature objectproperties- aJsonObjectcontaining the feature propertiesid- 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 aGeometry, optionally a set of properties, and a String which represents the objects id.- Parameters:
geometry- a single geometry which makes up this feature objectproperties- aJsonObjectcontaining the feature propertiesbbox- optionally include a bbox definition as a double arrayid- 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 returnFeature.
-
bbox
@Nullable public BoundingBox bbox()
A Feature Collection might have a member namedbboxto include information on the coordinate range for it'sFeatures. 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.
-
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
Geometrywhich 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 aJsonObjectand might be empty if no properties are provided.- Returns:
- a
JsonObjectwhich 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.
-
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 builtGsonobject- 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 membervalue- 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 membervalue- 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 membervalue- 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 membervalue- 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 membervalue- 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
propertyfrom 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:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-