Class Polygon<P extends Position>

  • All Implemented Interfaces:
    Serializable, Iterable<LinearRing<P>>, Complex<P,​LinearRing<P>>, Polygonal<P>

    public class Polygon<P extends Position>
    extends Geometry<P>
    implements Polygonal<P>, Complex<P,​LinearRing<P>>
    A planar surface defined by 1 exterior boundary and 0 or more interior boundaries. Each interior boundary defines a hole in the Polygon.

    The exterior boundary LinearRing defines the "top" of the surface which is the side of the surface from which the exterior boundary appears to traverse the boundary in a counter clockwise direction. The interior LinearRings will have the opposite orientation and appear as clockwise when viewed from the "top".

    The rules that define valid Polygons are as follows

    1. Polygons are topologically closed;
    2. The boundary of a Polygon consists of a set of LinearRings that make up its exterior and interior boundaries;
    3. No two rings in the boundary cross and the rings in the boundary of a Polygon may intersect at a Point but only as a tangent
    4. A Polygon may not have cut lines, spikes or punctures;
    5. The interior of every Polygon is a connected point set;
    6. The exterior of a Polygon with 1 or more holes is not connected. Each hole defines a connected component of the exterior
    Author:
    Karel Maesen, Geovise BVBA creation-date: 4/14/11
    See Also:
    Serialized Form
    • Constructor Detail

      • Polygon

        public Polygon​(PositionSequence<P> positionSequence,
                       CoordinateReferenceSystem<P> crs)
        Creates a Polygon with no holes, and having the specified PositionSequence as exterior boundary
        Parameters:
        positionSequence - the PositionSequence representing the exterior boundary
        Throws:
        IllegalArgumentException - when the specified PositionSequence does not form a LinearRing (i.e., is empty or not closed).
      • Polygon

        public Polygon​(LinearRing<P>... rings)
        Creates a Polygon with the specified array of exterior and interior boundaries.
        Parameters:
        rings - the array of the Polygon's boundaries: the first element is the exterior boundary, all subsequent rings represent interior boundaries.
        Throws:
        IllegalArgumentException - when the specified PositionSequence does not form a LinearRing (i.e., is empty or not closed).
    • Method Detail

      • getExteriorRing

        public LinearRing<P> getExteriorRing()
        Returns the exterior boundary of this Polygon.
        Returns:
        a LinearRing representing the exterior boundary of this Polygon.
      • getNumInteriorRing

        public int getNumInteriorRing()
        returns the number of interior boundaries.
        Returns:
        the number of interior boundaries
      • getInteriorRingN

        public LinearRing<P> getInteriorRingN​(int index)
        Returns the specified interior ring.
        Parameters:
        index - the (zero-based) position of the interior boundary in the list of interior boundaries.
        Returns:
        the LinearRing at the position specified by the parameter index.
      • getDimension

        public int getDimension()
        Description copied from class: Geometry
        Returns the topological dimension of this instance. In non-homogenous collections, this will return the largest topological dimension of the contained Geometries.
        Specified by:
        getDimension in class Geometry<P extends Position>
        Returns:
        the topological dimension of this instance
      • iterator

        public Iterator<LinearRing<P>> iterator()
        Returns an Iterator over the boundaries of this Polygon.

        The boundaries are returned in order, with the first element being the exterior boundary.

        Specified by:
        iterator in interface Iterable<P extends Position>
        Returns:
        an Iterator over the boundaries of this Polygon.
      • accept

        public void accept​(GeometryVisitor<P> visitor)
        Description copied from class: Geometry
        Accepts a GeometryVisitor.

        If this Geometry instance is a GeometryCollection then it will pass the visitor to its contained Geometries.

        Specified by:
        accept in class Geometry<P extends Position>
      • getNumGeometries

        public int getNumGeometries()
        Description copied from interface: Complex
        Returns the number of constituent Geometrys
        Specified by:
        getNumGeometries in interface Complex<P extends Position,​LinearRing<P extends Position>>
        Returns:
        the number of constituent Geometrys
      • getComponentType

        public Class<? extends Geometry> getComponentType()
        Description copied from interface: Complex
        Returns the Class of which all constituent Geometrys are instances.
        Specified by:
        getComponentType in interface Complex<P extends Position,​LinearRing<P extends Position>>
        Returns:
        the Class of which all constituent Geometrys are instances.