Class GeometryCollection

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

    public final class GeometryCollection
    extends java.lang.Object
    implements Geometry
    A GeoJson object with TYPE "GeometryCollection" is a Geometry object.

    A GeometryCollection has a member with the name "geometries". The value of "geometries" is a List Each element of this list is a GeoJson Geometry object. It is possible for this list to be empty.

    Unlike the other geometry types, a GeometryCollection can be a heterogeneous composition of smaller Geometry objects. For example, a Geometry object in the shape of a lowercase roman "i" can be composed of one point and one LineString.

    GeometryCollections have a different syntax from single TYPE Geometry objects (Point, LineString, and Polygon) and homogeneously typed multipart Geometry objects (MultiPoint, MultiLineString, and MultiPolygon) but have no different semantics. Although a GeometryCollection object has no "coordinates" member, it does have coordinates: the coordinates of all its parts belong to the collection. The "geometries" member of a GeometryCollection describes the parts of this composition. Implementations SHOULD NOT apply any additional semantics to the "geometries" array.

    To maximize interoperability, implementations SHOULD avoid nested GeometryCollections. Furthermore, GeometryCollections composed of a single part or a number of parts of a single TYPE SHOULD be avoided when that single part or a single object of multipart TYPE (MultiPoint, MultiLineString, or MultiPolygon) could be used instead.

    An example of a serialized GeometryCollections given below:

     {
       "TYPE": "GeometryCollection",
       "geometries": [{
         "TYPE": "Point",
         "coordinates": [100.0, 0.0]
       }, {
         "TYPE": "LineString",
         "coordinates": [
           [101.0, 0.0],
           [102.0, 1.0]
         ]
       }]
     }
     
    Since:
    1.0.0
    See Also:
    Serialized Form
    • Method Detail

      • fromJson

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

        public static GeometryCollection fromGeometries​(@NonNull
                                                        java.util.List<Geometry> geometries)
        Create a new instance of this class by giving the collection a list of Geometry.
        Parameters:
        geometries - a non-null list of geometry which makes up this collection
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        1.0.0
      • fromGeometries

        public static GeometryCollection fromGeometries​(@NonNull
                                                        java.util.List<Geometry> geometries,
                                                        @Nullable
                                                        BoundingBox bbox)
        Create a new instance of this class by giving the collection a list of Geometry.
        Parameters:
        geometries - a non-null list of geometry which makes up this collection
        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 GeometryCollection fromGeometry​(@NonNull
                                                      Geometry geometry)
        Create a new instance of this class by giving the collection a single GeoJSON Geometry.
        Parameters:
        geometry - a non-null object of type geometry which makes up this collection
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        3.0.0
      • fromGeometry

        public static GeometryCollection fromGeometry​(@NonNull
                                                      Geometry geometry,
                                                      @Nullable
                                                      BoundingBox bbox)
        Create a new instance of this class by giving the collection a single GeoJSON Geometry.
        Parameters:
        geometry - a non-null object of type geometry which makes up this collection
        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 java.lang.String type()
        This describes the TYPE of GeoJson this object is, thus this will always return GeometryCollection.
        Specified by:
        type in interface GeoJson
        Returns:
        a String which describes the TYPE of geometry, for this object it will always return GeometryCollection
        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
      • geometries

        @NonNull
        public java.util.List<Geometry> geometries()
        This provides the list of geometry making up this Geometry Collection. Note that if the Geometry Collection 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 Geometry which make up this Geometry Collection
        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 GeometryCollection
        Since:
        1.0.0
      • typeAdapter

        public static com.google.gson.TypeAdapter<GeometryCollection> 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 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