Class FeatureCollection

java.lang.Object
com.mapbox.geojson.FeatureCollection
All Implemented Interfaces:
GeoJson, Serializable

public final class FeatureCollection extends Object implements GeoJson
This represents a GeoJson Feature Collection which holds a list of Feature objects (when serialized the feature list becomes a JSON array).

Note that the feature list could potentially be empty. Features within the list must follow the specifications defined inside the Feature class.

An example of a Feature Collections given below:

 {
   "TYPE": "FeatureCollection",
   "bbox": [100.0, 0.0, -100.0, 105.0, 1.0, 0.0],
   "features": [
     //...
   ]
 }
 
Since:
1.0.0
See Also:
  • Method Details

    • fromJson

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

      public static FeatureCollection fromFeatures(@NonNull Feature[] features)
      Create a new instance of this class by giving the feature collection an array of Features. The array of features itself isn't null but it can be empty and have a length of 0.
      Parameters:
      features - an array of features
      Returns:
      a new instance of this class defined by the values passed inside this static factory method
      Since:
      1.0.0
    • fromFeatures

      public static FeatureCollection fromFeatures(@NonNull List<Feature> features)
      Create a new instance of this class by giving the feature collection a list of Features. The list of features itself isn't null but it can empty and have a size of 0.
      Parameters:
      features - a list of features
      Returns:
      a new instance of this class defined by the values passed inside this static factory method
      Since:
      1.0.0
    • fromFeatures

      public static FeatureCollection fromFeatures(@NonNull Feature[] features, @Nullable BoundingBox bbox)
      Create a new instance of this class by giving the feature collection an array of Features. The array of features itself isn't null but it can be empty and have a length of 0.
      Parameters:
      features - an array of features
      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:
      3.0.0
    • fromFeatures

      public static FeatureCollection fromFeatures(@NonNull List<Feature> features, @Nullable BoundingBox bbox)
      Create a new instance of this class by giving the feature collection a list of Features. The list of features itself isn't null but it can be empty and have a size of 0.
      Parameters:
      features - a list of features
      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:
      3.0.0
    • fromFeature

      public static FeatureCollection fromFeature(@NonNull Feature feature)
      Create a new instance of this class by giving the feature collection a single Feature.
      Parameters:
      feature - a single feature
      Returns:
      a new instance of this class defined by the values passed inside this static factory method
      Since:
      3.0.0
    • fromFeature

      public static FeatureCollection fromFeature(@NonNull Feature feature, @Nullable BoundingBox bbox)
      Create a new instance of this class by giving the feature collection a single Feature.
      Parameters:
      feature - a single feature
      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:
      3.0.0
    • type

      @NonNull public String type()
      This describes the type of GeoJson this object is, thus this will always return FeatureCollection.
      Specified by:
      type in interface GeoJson
      Returns:
      a String which describes the TYPE of GeoJson, for this object it will always return FeatureCollection
      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
    • features

      @Nullable public List<Feature> features()
      This provides the list of feature making up this Feature Collection. Note that if the FeatureCollection was created through fromJson(String) this list could be null. Otherwise, the list can't be null but the size of the list can equal 0.
      Returns:
      a list of Features which make up this Feature Collection
      Since:
      1.0.0
    • toJson

      public 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 Collection
      Since:
      1.0.0
    • typeAdapter

      public static com.google.gson.TypeAdapter<FeatureCollection> 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
    • toString

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object