Package com.mapbox.geojson
Class Feature
java.lang.Object
com.mapbox.geojson.Feature
- All Implemented Interfaces:
GeoJson,Serializable
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:
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddBooleanProperty(String key, Boolean value) Convenience method to add a Boolean member.voidaddCharacterProperty(String key, Character value) Convenience method to add a Character member.voidaddNumberProperty(String key, Number value) Convenience method to add a Number member.voidaddProperty(String key, com.google.gson.JsonElement value) Convenience method to add a JsonElement member.voidaddStringProperty(String key, String value) Convenience method to add a String member.bbox()A Feature Collection might have a member namedbboxto include information on the coordinate range for it'sFeatures.booleanstatic 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, 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, 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 FeatureCreate a new instance of this class by passing in a formatted valid JSON String.geometry()The geometry which makes up this feature.getBooleanProperty(String key) Convenience method to get a Boolean member.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.getNumberProperty(String key) Convenience method to get a Number member.com.google.gson.JsonElementgetProperty(String key) Convenience method to get a JsonElement member.getStringProperty(String key) Convenience method to get a String member.inthashCode()booleanConvenience method to check for a member by name as well as non-null value.booleanhasProperty(String key) Convenience method to check if a member with the specified name is present in this object.id()A feature may have a commonly used identifier which is either a unique String or number.com.google.gson.JsonObjectThis contains the JSON object which holds the feature properties.com.google.gson.JsonElementremoveProperty(String key) Removes the property from the object properties.toJson()This takes the currently defined values found inside this instance and converts it to a GeoJson string.toString()type()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 Details
-
fromJson
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
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
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 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 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
This describes the TYPE of GeoJson geometry this object is, thus this will always returnFeature. -
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
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
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
This takes the currently defined values found inside this instance and converts it to a GeoJson string. -
typeAdapter
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
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
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
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
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
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
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
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
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.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
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
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
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
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
-
equals
-
hashCode
public int hashCode()
-