public final class Feature extends java.lang.Object implements GeoJson
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" }
Modifier and Type | Method and 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 Feature s. |
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,
BoundingBox bbox)
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 |
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)
Convenience method to get a Character member.
|
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.
|
public static Feature fromJson(@NonNull java.lang.String json)
fromGeometry(Geometry)
.json
- a formatted valid JSON string defining a GeoJson Featurepublic static Feature fromGeometry(@Nullable Geometry geometry)
Geometry
.geometry
- a single geometry which makes up this feature objectpublic static Feature fromGeometry(@Nullable Geometry geometry, @Nullable BoundingBox bbox)
Geometry
. You can also pass
in a double array defining a bounding box.geometry
- a single geometry which makes up this feature objectbbox
- optionally include a bbox definition as a double arraypublic static Feature fromGeometry(@Nullable Geometry geometry, @Nullable com.google.gson.JsonObject properties)
Geometry
and optionally a
set of properties.geometry
- a single geometry which makes up this feature objectproperties
- a JsonObject
containing the feature propertiespublic static Feature fromGeometry(@Nullable Geometry geometry, @Nullable com.google.gson.JsonObject properties, @Nullable BoundingBox bbox)
Geometry
, optionally a
set of properties, and optionally pass in a bbox.geometry
- a single geometry which makes up this feature objectbbox
- optionally include a bbox definition as a double arrayproperties
- a JsonObject
containing the feature propertiespublic static Feature fromGeometry(@Nullable Geometry geometry, @Nullable com.google.gson.JsonObject properties, @Nullable java.lang.String id)
Geometry
, optionally a
set of properties, and a String which represents the objects id.geometry
- a single geometry which makes up this feature objectproperties
- a JsonObject
containing the feature propertiesid
- common identifier of this featureFeature
public static Feature fromGeometry(@Nullable Geometry geometry, @NonNull com.google.gson.JsonObject properties, @Nullable java.lang.String id, @Nullable BoundingBox bbox)
Geometry
, optionally a
set of properties, and a String which represents the objects id.geometry
- a single geometry which makes up this feature objectproperties
- a JsonObject
containing the feature propertiesbbox
- optionally include a bbox definition as a double arrayid
- common identifier of this featureFeature
@NonNull public java.lang.String type()
Feature
.@Nullable public BoundingBox bbox()
bbox
to include information on the
coordinate range for it's Feature
s. 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.@Nullable public java.lang.String id()
@Nullable public Geometry geometry()
Geometry
which makes this feature spatially aware@Nullable public com.google.gson.JsonObject properties()
JsonObject
and might be empty if no properties are provided.JsonObject
which holds this features current propertiespublic java.lang.String toJson()
public static com.google.gson.TypeAdapter<Feature> typeAdapter(com.google.gson.Gson gson)
gson
- the built Gson
objectpublic void addStringProperty(java.lang.String key, java.lang.String value)
key
- name of the membervalue
- the String value associated with the memberpublic void addNumberProperty(java.lang.String key, java.lang.Number value)
key
- name of the membervalue
- the Number value associated with the memberpublic void addBooleanProperty(java.lang.String key, java.lang.Boolean value)
key
- name of the membervalue
- the Boolean value associated with the memberpublic void addCharacterProperty(java.lang.String key, java.lang.Character value)
key
- name of the membervalue
- the Character value associated with the memberpublic void addProperty(java.lang.String key, com.google.gson.JsonElement value)
key
- name of the membervalue
- the JsonElement value associated with the memberpublic java.lang.String getStringProperty(java.lang.String key)
key
- name of the memberpublic java.lang.Number getNumberProperty(java.lang.String key)
key
- name of the memberpublic java.lang.Boolean getBooleanProperty(java.lang.String key)
key
- name of the memberpublic java.lang.Character getCharacterProperty(java.lang.String key)
key
- name of the memberpublic com.google.gson.JsonElement getProperty(java.lang.String key)
key
- name of the memberpublic com.google.gson.JsonElement removeProperty(java.lang.String key)
key
- name of the memberproperty
from the key string passed in through the parameter.public boolean hasProperty(java.lang.String key)
key
- name of the memberpublic boolean hasNonNullValueForProperty(java.lang.String key)
key
- name of the memberpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object