Class MultiPolygon

  • All Implemented Interfaces:
    CoordinateContainer<java.util.List<java.util.List<java.util.List<Point>>>>, GeoJson, Geometry, java.io.Serializable

    public final class MultiPolygon
    extends java.lang.Object
    implements CoordinateContainer<java.util.List<java.util.List<java.util.List<Point>>>>
    A multiPolygon is an array of Polygon coordinate arrays.

    This adheres to the RFC 7946 internet standard when serialized into JSON. When deserialized, this class becomes an immutable object which should be initiated using its static factory methods.

    When representing a Polygon that crosses the antimeridian, interoperability is improved by modifying their geometry. Any geometry that crosses the antimeridian SHOULD be represented by cutting it in two such that neither part's representation crosses the antimeridian.

    For example, a line extending from 45 degrees N, 170 degrees E across the antimeridian to 45 degrees N, 170 degrees W should be cut in two and represented as a MultiLineString.

    A sample GeoJson MultiPolygon's provided below (in it's serialized state).

     {
       "type": "MultiPolygon",
       "coordinates": [
         [
           [
             [102.0, 2.0],
             [103.0, 2.0],
             [103.0, 3.0],
             [102.0, 3.0],
             [102.0, 2.0]
           ]
         ],
         [
           [
             [100.0, 0.0],
             [101.0, 0.0],
             [101.0, 1.0],
             [100.0, 1.0],
             [100.0, 0.0]
           ],
           [
             [100.2, 0.2],
             [100.2, 0.8],
             [100.8, 0.8],
             [100.8, 0.2],
             [100.2, 0.2]
           ]
         ]
       ]
     }
     
    Look over the Polygon documentation to get more information about formatting your list of Polygon objects correctly.
    Since:
    1.0.0
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      BoundingBox bbox()
      A Feature Collection might have a member named bbox to include information on the coordinate range for it's Features.
      java.util.List<java.util.List<java.util.List<Point>>> coordinates()
      Provides the list of list of list of Points that make up the MultiPolygon geometry.
      boolean equals​(java.lang.Object obj)  
      static MultiPolygon fromJson​(java.lang.String json)
      Create a new instance of this class by passing in a formatted valid JSON String.
      static MultiPolygon fromLngLats​(java.util.List<java.util.List<java.util.List<Point>>> points)
      Create a new instance of this class by defining a list of a list of a list of Points which follow the correct specifications described in the Point documentation.
      static MultiPolygon fromLngLats​(java.util.List<java.util.List<java.util.List<Point>>> points, BoundingBox bbox)
      Create a new instance of this class by defining a list of a list of a list of Points which follow the correct specifications described in the Point documentation.
      static MultiPolygon fromPolygon​(Polygon polygon)
      Create a new instance of this class by defining a single Polygon objects and passing it in as a parameter in this method.
      static MultiPolygon fromPolygon​(Polygon polygon, BoundingBox bbox)
      Create a new instance of this class by defining a single Polygon objects and passing it in as a parameter in this method.
      static MultiPolygon fromPolygons​(java.util.List<Polygon> polygons)
      Create a new instance of this class by defining a list of Polygon objects and passing that list in as a parameter in this method.
      static MultiPolygon fromPolygons​(java.util.List<Polygon> polygons, BoundingBox bbox)
      Create a new instance of this class by defining a list of Polygon objects and passing that list in as a parameter in this method.
      int hashCode()  
      java.util.List<Polygon> polygons()
      Returns a list of polygons which make up this MultiPolygon instance.
      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 MultiPolygon.
      static com.google.gson.TypeAdapter<MultiPolygon> typeAdapter​(com.google.gson.Gson gson)
      Gson TYPE adapter for parsing Gson to this class.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • fromJson

        public static MultiPolygon 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 MultiPolygon object from scratch it is better to use one of the other provided static factory methods such as fromPolygons(List).
        Parameters:
        json - a formatted valid JSON string defining a GeoJson MultiPolygon
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        1.0.0
      • fromPolygons

        public static MultiPolygon fromPolygons​(@NonNull
                                                java.util.List<Polygon> polygons)
        Create a new instance of this class by defining a list of Polygon objects and passing that list in as a parameter in this method. The Polygons should comply with the GeoJson specifications described in the documentation.
        Parameters:
        polygons - a list of Polygons which make up this MultiPolygon
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        3.0.0
      • fromPolygons

        public static MultiPolygon fromPolygons​(@NonNull
                                                java.util.List<Polygon> polygons,
                                                @Nullable
                                                BoundingBox bbox)
        Create a new instance of this class by defining a list of Polygon objects and passing that list in as a parameter in this method. The Polygons should comply with the GeoJson specifications described in the documentation. Optionally, pass in an instance of a BoundingBox which better describes this MultiPolygon.
        Parameters:
        polygons - a list of Polygons which make up this MultiPolygon
        bbox - optionally include a bbox definition
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        3.0.0
      • fromPolygon

        public static MultiPolygon fromPolygon​(@NonNull
                                               Polygon polygon)
        Create a new instance of this class by defining a single Polygon objects and passing it in as a parameter in this method. The Polygon should comply with the GeoJson specifications described in the documentation.
        Parameters:
        polygon - a single Polygon which make up this MultiPolygon
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        3.0.0
      • fromPolygon

        public static MultiPolygon fromPolygon​(@NonNull
                                               Polygon polygon,
                                               @Nullable
                                               BoundingBox bbox)
        Create a new instance of this class by defining a single Polygon objects and passing it in as a parameter in this method. The Polygon should comply with the GeoJson specifications described in the documentation.
        Parameters:
        polygon - a single Polygon which make up this MultiPolygon
        bbox - optionally include a bbox definition
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        3.0.0
      • fromLngLats

        public static MultiPolygon fromLngLats​(@NonNull
                                               java.util.List<java.util.List<java.util.List<Point>>> points)
        Create a new instance of this class by defining a list of a list of a list of Points which follow the correct specifications described in the Point documentation.
        Parameters:
        points - a list of Points which make up the MultiPolygon geometry
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        3.0.0
      • fromLngLats

        public static MultiPolygon fromLngLats​(@NonNull
                                               java.util.List<java.util.List<java.util.List<Point>>> points,
                                               @Nullable
                                               BoundingBox bbox)
        Create a new instance of this class by defining a list of a list of a list of Points which follow the correct specifications described in the Point documentation.
        Parameters:
        points - a list of Points which make up the MultiPolygon geometry
        bbox - optionally include a bbox definition
        Returns:
        a new instance of this class defined by the values passed inside this static factory method
        Since:
        3.0.0
      • polygons

        public java.util.List<Polygon> polygons()
        Returns a list of polygons which make up this MultiPolygon instance.
        Returns:
        a list of Polygons which make up this MultiPolygon instance
        Since:
        3.0.0
      • type

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

        @NonNull
        public java.util.List<java.util.List<java.util.List<Point>>> coordinates()
        Provides the list of list of list of Points that make up the MultiPolygon geometry.
        Specified by:
        coordinates in interface CoordinateContainer<java.util.List<java.util.List<java.util.List<Point>>>>
        Returns:
        a list of points
        Since:
        3.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 MultiPolygon geometry
        Since:
        1.0.0
      • typeAdapter

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