Class Polygon

All Implemented Interfaces:
AutoCloseable

public final class Polygon extends CompositePatch implements AutoCloseable
Represents a polygon.
See Also:
  • Method Details

    • finalize

      protected void finalize()
      Overrides:
      finalize in class CompositePatch
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class CompositePatch
    • replaceExteriorRing

      @NotNull public Polygon replaceExteriorRing(@NotNull PolylineRing exteriorRing) throws NullPointerException
      Creates a new Polygon instance using the interior rings from this instance, but with a new exterior ring.
      Parameters:
      exteriorRing - the new exterior ring.
      Returns:
      a new Polyline instance.
      Throws:
      NullPointerException - when passing null.
      Since:
      2024.1
    • replaceInteriorRing

      @NotNull public Polygon replaceInteriorRing(long index, @NotNull PolylineRing interiorRing) throws NullPointerException, IllegalArgumentException
      Creates a new Polygon instance with the exterior and interior rings from this instance, but with a new interior ring at location 'index'.
      Parameters:
      index - the index of the interior ring to replace
      interiorRing - the new interior ring.
      Returns:
      a new Polyline instance
      Throws:
      NullPointerException - when passing null.
      IllegalArgumentException - for an invalid index
      Since:
      2024.1
    • appendInteriorRing

      @NotNull public Polygon appendInteriorRing(@NotNull PolylineRing interiorRing) throws NullPointerException
      Creates a new Polygon instance based on this instance, but with a new interior ring appended to the list of interior rings.
      Parameters:
      interiorRing - the new interior ring.
      Returns:
      a new Polyline instance, with a new interior ring.
      Throws:
      NullPointerException - when passing null.
      Since:
      2024.1
    • removeInteriorRing

      @NotNull public Polygon removeInteriorRing(long index) throws IllegalArgumentException
      Creates a new Polygon instance based on this instance, but with the interior ring at location 'index' removed.
      Parameters:
      index - the index of the interior ring to remove
      Returns:
      a new Polyline instance, with the interior ring at location 'index' removed.
      Throws:
      IllegalArgumentException - for an invalid index
      Since:
      2024.1
    • getArea

      public double getArea() throws IllegalArgumentException
      Returns the 2D area of this polygon.

      The calculations are performed in the coordinate reference of this geometry. This means that

      • for geodetic references, the curvature of the line segments are taken into account
      • for other references, the calculations are cartesian.

      The returned value is expressed in the unit of measure of the reference of this geometry.

      • for geodetic references, this is always meters.
      • or other references this is typically meters, but depending on the reference the unit of measure can also be something else like millimeters or feet.

      Limitations:

      • The area calculation is performed in 2D. For 3D polygons, the z value will be ignored and considered as 0.
      • For this reason, geometries with a geocentric reference are not supported at all. In this case, an exception is thrown.
      • Geometries with a rhumb line interpolation type are not supported. In this case, an exception is thrown.
      • The calculations assume non-degenerare polygons. This means that the exterior and interior rings are not self intersecting, and that none of the (exterior or interior) rings overlap with other (exterior or interior) rings. The calculations will still produce a result, though it will not be well-defined (since the input is also no well-defined).
      Returns:
      the 2D area of this polygon.
      Throws:
      IllegalArgumentException - when using this method on a geometry with a geocentric reference, or with a rhumb interpolation type.
      Since:
      2025.0