All Implemented Interfaces:
Comparable<Geometry>

public final class Polygon extends Surface
A polygon geometry representing an area enclosed by a shell with optional holes. Polygons are immutable. Each ring must be closed (first and last points equal) and have at least 4 points.
Since:
4.0.0
  • Method Details

    • of

      public static Polygon of(LineString shell, LineString... holes)
      Creates a polygon from a shell ring and optional hole rings. All rings must be closed (first and last point equal) and have at least 4 points. All rings must have the same SRID and z-dimension flag. A hole ring must not be empty, and an empty shell is only valid for a polygon with no holes.
      Parameters:
      shell - the exterior ring
      holes - the interior rings (holes)
      Returns:
      the polygon
      Throws:
      IllegalArgumentException - if shell is null, if holes is null or holds a null element, if a ring that is not empty has fewer than 4 points or does not have equal first and last points, if any hole is empty, if shell is empty and any hole is given, or if the rings do not all have the same SRID and the same z dimension
      Since:
      4.0.0
    • empty

      public static Polygon empty()
      Creates an empty polygon with Model.CARTESIAN model.
      Returns:
      an empty polygon
      Since:
      4.0.0
    • empty

      public static Polygon empty(Model model)
      Creates an empty polygon with the specified model.
      Parameters:
      model - Model.CARTESIAN or Model.GEOGRAPHIC
      Returns:
      an empty polygon
      Throws:
      IllegalArgumentException - if model is Model.OTHER or null
      Since:
      4.0.0
    • exteriorRing

      public LineString exteriorRing()
      Returns the exterior ring (shell) of this polygon.
      Returns:
      the exterior ring, an empty line string when this polygon is empty
      Since:
      4.0.0
    • interiorRings

      public List<LineString> interiorRings()
      Returns an unmodifiable list of interior rings (holes).
      Returns:
      the holes, an empty list when this polygon has no holes
      Since:
      4.0.0
    • isEmpty

      public boolean isEmpty()
      Description copied from class: Geometry
      Returns true if this geometry is empty (has no coordinates). For collections, returns true if all parts are empty.
      Specified by:
      isEmpty in class Geometry
      Returns:
      true if empty
    • equals

      public boolean equals(Object o)
      Description copied from class: Geometry
      Exact equality: same type, same SRID, same coordinates (including z flag). Coordinates are compared numerically, so -0.0 equals 0.0.
      Specified by:
      equals in class Geometry
    • hashCode

      public int hashCode()
      Description copied from class: Geometry
      Hash code consistent with equals. Zero values are normalized so -0.0 and 0.0 hash alike.
      Specified by:
      hashCode in class Geometry