Class Polygon

  • All Implemented Interfaces:
    Geometry

    public class Polygon
    extends java.lang.Object
    implements Geometry
    This class represents either a simple polygon enclosing an area, or a more complex polygon that contains both an exterior boundary and interior boundaries (holes) within it. It will be persisted into the database according to the specification.

    The factory for creating a Polygon is PolygonBuilder, which is accessible via the GeoJson.polygonBuilder method. Alternatively, simple polygons without inner rings can be created via the GeoJson.polygon factory method.

    See Also:
    GeoJson.polygon(LineString, LineString...), GeoJson.polygon(Point...)
    • Method Detail

      • getCoordinates

        public java.util.List<LineString> getCoordinates()
        Description copied from interface: Geometry
        Returns a list of coordinates for this Geometry type. For something like a Point, this will be a pair of lat/long coordinates, but for more complex types this will be a list of other Geometry objects. Used for serialisation to MongoDB.
        Specified by:
        getCoordinates in interface Geometry
        Returns:
        a List containing either Geometry objects, or a pair of coordinates as doubles
      • getExteriorBoundary

        public LineString getExteriorBoundary()
        Returns a LineString representing the exterior boundary of this Polygon. Polygons should have an exterior boundary where the end point is the same as the start point.
        Returns:
        a LineString containing the points that make up the external boundary of this Polygon.
      • getInteriorBoundaries

        public java.util.List<LineString> getInteriorBoundaries()
        Returns a (possibly empty) List of LineStrings, one for each hole inside the external boundary of this polygon.
        Returns:
        a List of LineStrings where each LineString represents an internal boundary or hole.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • convert

        public com.mongodb.client.model.geojson.Polygon convert()
        Description copied from interface: Geometry
        Converts this type to the driver type
        Specified by:
        convert in interface Geometry
        Returns:
        the driver type
      • convert

        public com.mongodb.client.model.geojson.Polygon convert​(CoordinateReferenceSystem crs)
        Description copied from interface: Geometry
        Converts this type to the driver type
        Specified by:
        convert in interface Geometry
        Parameters:
        crs - the CRS to use
        Returns:
        the driver type