Class Polygon

All Implemented Interfaces:
Geometry, PolygonTypeGeometry, Surface, Serializable, Cloneable
Direct Known Subclasses:
OrientedRectangle

public class Polygon extends DefaultGeometry implements Surface, PolygonTypeGeometry
The Polygon class defines a polygon in a 2D space.
It is defined by a exterior ring and a set of non-intersecting rings called holes contained in the exterior ring.
A hole can intersect the exterior ring only on a single point.
See Also:
  • Field Details

    • rings

      protected LinearRing[] rings
      the rings defining the polygon. The first is the exterior Ring, others are the holes
  • Constructor Details

    • Polygon

      public Polygon()
    • Polygon

      public Polygon(LinearRing ring)
      Constructs a Polygon given a single ring, doesn't check if it's valid !
      Parameters:
      ring -
    • Polygon

      public Polygon(LinearRing[] rings)
      Constructs a Polygon given rings, doesn't check if it's valid !
      Parameters:
      rings -
    • Polygon

      public Polygon(double[][] tab)
      Constructs a Polygon given a matrix of double (rings made of points, points are entered as x y in the array), doesn't check if it's valid !
      Parameters:
      tab -
  • Method Details

    • getBounds

      public Rectangle getBounds()
      Returns the bounding box
      Specified by:
      getBounds in interface Geometry
      Returns:
      the bounding box of this geometry.
    • validate

      public boolean validate()
      validate this polygon
      ie test if it autointersects and if holes crosse the exteriorRing
      Returns:
    • createBounds

      public void createBounds()
      creates the bounding box
      called in the constructor, not needed from outside
      Specified by:
      createBounds in interface Geometry
    • centroid

      public Point centroid()
      Computes the centroid (center of mass) of the polygon, considering possibles holes in it.
      it also computes Area, available with getTempArea if needed
      Specified by:
      centroid in interface PolygonTypeGeometry
      Specified by:
      centroid in interface Surface
      Returns:
      the center of mass
    • area

      public double area()
      Computes the area of this Polygon
      Specified by:
      area in interface Geometry
      Specified by:
      area in interface PolygonTypeGeometry
      Specified by:
      area in interface Surface
      Returns:
      the area of this polygon
    • length

      public double length()
      Description copied from interface: Geometry
      Returns the geometry length. If the geometry is a surface, then the geometry perimeter shall be returned.
      Specified by:
      length in interface Geometry
      Returns:
      the geometry length.
    • clone

      public Polygon clone()
      Clones the current polygon object.
      Specified by:
      clone in interface Geometry
      Specified by:
      clone in class DefaultGeometry
      Returns:
    • serialize

      public Point[] serialize()
      This polygon as an array of Point
      Specified by:
      serialize in interface Geometry
      Returns:
      this geometry as an array of Point.
    • exteriorRing

      public LinearRing exteriorRing()
      The Exterior Ring
      Returns:
    • numInteriorRing

      public int numInteriorRing()
      The number of holes
      Returns:
    • interiorRingN

      public LinearRing interiorRingN(int N)
    • boundary

      public Geometry boundary()
      The boundary (!= boundingBox) of this polygon
      Specified by:
      boundary in interface Geometry
      Returns:
      a MultiLineString object describing the boundary of the polygon
    • pointOnSurface

      public Point pointOnSurface()
      a Point on this Polygon, in fact the first of the exteriorRing (not in the interior)
      Specified by:
      pointOnSurface in interface PolygonTypeGeometry
      Specified by:
      pointOnSurface in interface Surface
      Returns:
      a point on thge surface.
    • getRings

      public LinearRing[] getRings()
      The rings defining this polygon
      Returns:
    • setRings

      public void setRings(LinearRing[] rings)
      Parameters:
      rings -
    • hasHoles

      public boolean hasHoles()
    • spatiallyEquals

      public boolean spatiallyEquals(Geometry geometry, PrecisionModel precisionModel)
      Tests if this Polygon is equal to the argument, on a topological point of vue
      it means that they represents the same geometry, even if it is described differently (direction of the rings, order of the rings)
      it does not remove additional points on lineString (3 points aligned), one must use smoother.removeExtraPoints() before in order to achieve that.
      Specified by:
      spatiallyEquals in interface Geometry
      Parameters:
      geometry -
      precisionModel - the precision model to use while comparing geometries.
      Returns:
      whether both geometries are spatially equals.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Description copied from interface: Geometry
      Returns information about the current geometry.
      Specified by:
      toString in interface Geometry
      Overrides:
      toString in class Object
      Returns:
      information about the current geometry.
    • polygonIterator

      public PolygonGeometryIterator polygonIterator()
      Specified by:
      polygonIterator in interface PolygonTypeGeometry
    • translate

      public void translate(double dx, double dy)
      Translate this Polygon
      Specified by:
      translate in interface Geometry
      Parameters:
      dx - : translation on the X-axis
      dy - : translation on the Y-axis
    • getGeometryId

      public short getGeometryId()
      Description copied from interface: Geometry
      Returns the geometry class id. This method is useful for geometry serialization.
      Specified by:
      getGeometryId in interface Geometry
      Returns:
      the geometry id.
    • getGeometryType

      public int getGeometryType()
      Description copied from interface: Geometry
      Returns the geometry type for this geometry.
      Specified by:
      getGeometryType in interface Geometry
      Returns:
      the geometry type.
      See Also:
    • transform

      public Geometry transform(Transformation tr)
      Creates a clone of the current polygon and returns the new instance transformed with the specified geometry transformation.
      The returned geometry can be of any geometry types after the transformation.
      Specified by:
      transform in interface Geometry
      Parameters:
      tr - the transformation to apply.
      Returns:
      the newly created and transformed geometry instance.
    • getCenteredPoint

      public Point getCenteredPoint()
      Description copied from interface: Geometry
      This method returns a point that is typically centered on the geometry. If the geometry is a point, the point is returned. If it is a line, a point on the curve interpolated at 50% is returned. If the geometry is a surface, the centroid is returned if it is inside the polygon, if not, a point inside the polygon (but likely not exactly in the center) will be returned. If the geometry is a collection, the method is called on the first part of the collection.
      Specified by:
      getCenteredPoint in interface Geometry
      Returns:
      a point likely at the center of the geometry
      See Also:
    • sizeOf

      public int sizeOf()
      Returns an approximation in bytes of the memory used by this geometry.
      Specified by:
      sizeOf in interface Geometry
      Returns:
      the memory used by this geometry.
    • asText

      public String asText()
      Description copied from class: DefaultGeometry
      Returns this geometry encoded using the Well-Known Text (WKT) standard.
      Specified by:
      asText in interface Geometry
      Overrides:
      asText in class DefaultGeometry
      Returns:
      a WKT geometry.