Class Polygon
- java.lang.Object
-
- org.locationtech.jts.geom.Geometry
-
- org.locationtech.jts.geom.Polygon
-
- All Implemented Interfaces:
Serializable,Cloneable,Comparable,Polygonal
public class Polygon extends Geometry implements Polygonal
Represents a polygon with linear edges, which may include holes. The outer boundary (shell) and inner boundaries (holes) of the polygon are represented byLinearRings. The boundary rings of the polygon may have any orientation. Polygons are closed, simple geometries by definition.The polygon model conforms to the assertions specified in the OpenGIS Simple Features Specification for SQL.
A
Polygonis topologically valid if and only if:- the coordinates which define it are valid coordinates
- the linear rings for the shell and holes are valid (i.e. are closed and do not self-intersect)
- holes touch the shell or another hole at at most one point (which implies that the rings of the shell and holes must not cross)
- the interior of the polygon is connected, or equivalently no sequence of touching holes makes the interior of the polygon disconnected (i.e. effectively split the polygon into two pieces).
- Version:
- 1.7
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected LinearRing[]holesThe interior boundaries, if any.protected LinearRingshellThe exterior boundary, ornullif thisPolygonis empty.
-
Constructor Summary
Constructors Constructor Description Polygon(LinearRing shell, LinearRing[] holes, GeometryFactory factory)Constructs aPolygonwith the given exterior boundary and interior boundaries.Polygon(LinearRing shell, LinearRing[] holes, PrecisionModel precisionModel, int SRID)Deprecated.Use GeometryFactory insteadPolygon(LinearRing shell, PrecisionModel precisionModel, int SRID)Deprecated.Use GeometryFactory instead
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidapply(CoordinateFilter filter)Performs an operation with or on thisGeometry's coordinates.voidapply(CoordinateSequenceFilter filter)Performs an operation on the coordinates in thisGeometry'sCoordinateSequences.voidapply(GeometryComponentFilter filter)Performs an operation with or on this Geometry and its component Geometry's.voidapply(GeometryFilter filter)Performs an operation with or on thisGeometryand its subelementGeometrys (if any).Objectclone()Deprecated.protected intcompareToSameClass(Object o)Returns whether thisGeometryis greater than, equal to, or less than anotherGeometryhaving the same class.protected intcompareToSameClass(Object o, CoordinateSequenceComparator comp)Returns whether thisGeometryis greater than, equal to, or less than anotherGeometryof the same class.protected EnvelopecomputeEnvelopeInternal()Returns the minimum and maximum x and y values in thisGeometry, or a nullEnvelopeif thisGeometryis empty.GeometryconvexHull()Computes the smallest convexPolygonthat contains all the points in theGeometry.protected PolygoncopyInternal()An internal method to copy subclass-specific geometry data.booleanequalsExact(Geometry other, double tolerance)Returns true if the twoGeometrys are exactly equal, up to a specified distance tolerance.doublegetArea()Returns the area of thisPolygonGeometrygetBoundary()Computes the boundary of this geometryintgetBoundaryDimension()Returns the dimension of thisGeometrys inherent boundary.CoordinategetCoordinate()Returns a vertex of thisGeometry(usually, but not necessarily, the first one).Coordinate[]getCoordinates()Returns an array containing the values of all the vertices for this geometry.intgetDimension()Returns the dimension of this geometry.LineStringgetExteriorRing()StringgetGeometryType()Returns the name of this Geometry's actual class.LineStringgetInteriorRingN(int n)doublegetLength()Returns the perimeter of thisPolygonintgetNumInteriorRing()intgetNumPoints()Returns the count of thisGeometrys vertices.protected intgetSortIndex()booleanisEmpty()Tests whether the set of points covered by thisGeometryis empty.booleanisRectangle()Tests if a valid polygon is simple.voidnormalize()Converts thisGeometryto normal form (or canonical form ).Geometryreverse()Computes a new geometry which has all component coordinate sequences in reverse order (opposite orientation) to this one.-
Methods inherited from class org.locationtech.jts.geom.Geometry
buffer, buffer, buffer, checkNotGeometryCollection, compare, compareTo, compareTo, contains, copy, coveredBy, covers, crosses, difference, disjoint, distance, equal, equals, equals, equalsExact, equalsNorm, equalsTopo, geometryChanged, geometryChangedAction, getCentroid, getEnvelope, getEnvelopeInternal, getFactory, getGeometryN, getInteriorPoint, getNumGeometries, getPrecisionModel, getSRID, getUserData, hashCode, hasNonEmptyElements, hasNullElements, intersection, intersects, isEquivalentClass, isGeometryCollection, isSimple, isValid, isWithinDistance, norm, overlaps, relate, relate, setSRID, setUserData, symDifference, toString, toText, touches, union, union, within
-
-
-
-
Field Detail
-
shell
protected LinearRing shell
The exterior boundary, ornullif thisPolygonis empty.
-
holes
protected LinearRing[] holes
The interior boundaries, if any. This instance var is never null. If there are no holes, the array is of zero length.
-
-
Constructor Detail
-
Polygon
public Polygon(LinearRing shell, PrecisionModel precisionModel, int SRID)
Deprecated.Use GeometryFactory insteadConstructs aPolygonwith the given exterior boundary.- Parameters:
shell- the outer boundary of the newPolygon, ornullor an emptyLinearRingif the empty geometry is to be created.precisionModel- the specification of the grid of allowable points for thisPolygonSRID- the ID of the Spatial Reference System used by thisPolygon
-
Polygon
public Polygon(LinearRing shell, LinearRing[] holes, PrecisionModel precisionModel, int SRID)
Deprecated.Use GeometryFactory insteadConstructs aPolygonwith the given exterior boundary and interior boundaries.- Parameters:
shell- the outer boundary of the newPolygon, ornullor an emptyLinearRingif the empty geometry is to be created.holes- the inner boundaries of the newPolygon, ornullor emptyLinearRings if the empty geometry is to be created.precisionModel- the specification of the grid of allowable points for thisPolygonSRID- the ID of the Spatial Reference System used by thisPolygon
-
Polygon
public Polygon(LinearRing shell, LinearRing[] holes, GeometryFactory factory)
Constructs aPolygonwith the given exterior boundary and interior boundaries.- Parameters:
shell- the outer boundary of the newPolygon, ornullor an emptyLinearRingif the empty geometry is to be created.holes- the inner boundaries of the newPolygon, ornullor emptyLinearRings if the empty geometry is to be created.
-
-
Method Detail
-
getCoordinate
public Coordinate getCoordinate()
Description copied from class:GeometryReturns a vertex of thisGeometry(usually, but not necessarily, the first one). The returned coordinate should not be assumed to be an actual Coordinate object used in the internal representation.- Specified by:
getCoordinatein classGeometry- Returns:
- a
Coordinatewhich is a vertex of thisGeometry.
-
getCoordinates
public Coordinate[] getCoordinates()
Description copied from class:GeometryReturns an array containing the values of all the vertices for this geometry. If the geometry is a composite, the array will contain all the vertices for the components, in the order in which the components occur in the geometry.In general, the array cannot be assumed to be the actual internal storage for the vertices. Thus modifying the array may not modify the geometry itself. Use the
CoordinateSequence.setOrdinate(int, int, double)method (possibly on the components) to modify the underlying data. If the coordinates are modified,Geometry.geometryChanged()must be called afterwards.- Specified by:
getCoordinatesin classGeometry- Returns:
- the vertices of this
Geometry - See Also:
Geometry.geometryChanged(),CoordinateSequence.setOrdinate(int, int, double)
-
getNumPoints
public int getNumPoints()
Description copied from class:GeometryReturns the count of thisGeometrys vertices. TheGeometrys contained by compositeGeometrys must be Geometry's; that is, they must implementgetNumPoints- Specified by:
getNumPointsin classGeometry- Returns:
- the number of vertices in this
Geometry
-
getDimension
public int getDimension()
Description copied from class:GeometryReturns the dimension of this geometry. The dimension of a geometry is is the topological dimension of its embedding in the 2-D Euclidean plane. In the JTS spatial model, dimension values are in the set {0,1,2}.Note that this is a different concept to the dimension of the vertex
Coordinates. The geometry dimension can never be greater than the coordinate dimension. For example, a 0-dimensional geometry (e.g. a Point) may have a coordinate dimension of 3 (X,Y,Z).- Specified by:
getDimensionin classGeometry- Returns:
- the topological dimension of this geometry.
-
getBoundaryDimension
public int getBoundaryDimension()
Description copied from class:GeometryReturns the dimension of thisGeometrys inherent boundary.- Specified by:
getBoundaryDimensionin classGeometry- Returns:
- the dimension of the boundary of the class implementing this
interface, whether or not this object is the empty geometry. Returns
Dimension.FALSEif the boundary is the empty geometry.
-
isEmpty
public boolean isEmpty()
Description copied from class:GeometryTests whether the set of points covered by thisGeometryis empty.
-
isRectangle
public boolean isRectangle()
Tests if a valid polygon is simple. This method always returns true, since a valid polygon is always simple- Overrides:
isRectanglein classGeometry- Returns:
true
-
getExteriorRing
public LineString getExteriorRing()
-
getNumInteriorRing
public int getNumInteriorRing()
-
getInteriorRingN
public LineString getInteriorRingN(int n)
-
getGeometryType
public String getGeometryType()
Description copied from class:GeometryReturns the name of this Geometry's actual class.- Specified by:
getGeometryTypein classGeometry- Returns:
- the name of this
Geometrys actual class
-
getArea
public double getArea()
Returns the area of thisPolygon
-
getLength
public double getLength()
Returns the perimeter of thisPolygon
-
getBoundary
public Geometry getBoundary()
Computes the boundary of this geometry- Specified by:
getBoundaryin classGeometry- Returns:
- a lineal geometry (which may be empty)
- See Also:
Geometry.getBoundary()
-
computeEnvelopeInternal
protected Envelope computeEnvelopeInternal()
Description copied from class:GeometryReturns the minimum and maximum x and y values in thisGeometry, or a nullEnvelopeif thisGeometryis empty. UnlikegetEnvelopeInternal, this method calculates theEnvelopeeach time it is called;getEnvelopeInternalcaches the result of this method.- Specified by:
computeEnvelopeInternalin classGeometry- Returns:
- this
Geometrys bounding box; if theGeometryis empty,Envelope#isNullwill returntrue
-
equalsExact
public boolean equalsExact(Geometry other, double tolerance)
Description copied from class:GeometryReturns true if the twoGeometrys are exactly equal, up to a specified distance tolerance. Two Geometries are exactly equal within a distance tolerance if and only if:- they have the same structure
- they have the same values for their vertices, within the given tolerance distance, in exactly the same order.
GeometryFactory, theSRID, or theuserDatafields.To properly test equality between different geometries, it is usually necessary to
Geometry.normalize()them first.- Specified by:
equalsExactin classGeometry- Parameters:
other- theGeometrywith which to compare thisGeometrytolerance- distance at or below which twoCoordinates are considered equal- Returns:
trueif this and the otherGeometryhave identical structure and point values, up to the distance tolerance.- See Also:
Geometry.equalsExact(Geometry),Geometry.normalize(),Geometry.norm()
-
apply
public void apply(CoordinateFilter filter)
Description copied from class:GeometryPerforms an operation with or on thisGeometry's coordinates. If this method modifies any coordinate values,Geometry.geometryChanged()must be called to update the geometry state. Note that you cannot use this method to modify this Geometry if its underlying CoordinateSequence's #get method returns a copy of the Coordinate, rather than the actual Coordinate stored (if it even stores Coordinate objects at all).
-
apply
public void apply(CoordinateSequenceFilter filter)
Description copied from class:GeometryPerforms an operation on the coordinates in thisGeometry'sCoordinateSequences. If the filter reports that a coordinate value has been changed,Geometry.geometryChanged()will be called automatically.
-
apply
public void apply(GeometryFilter filter)
Description copied from class:GeometryPerforms an operation with or on thisGeometryand its subelementGeometrys (if any). Only GeometryCollections and subclasses have subelement Geometry's.
-
apply
public void apply(GeometryComponentFilter filter)
Description copied from class:GeometryPerforms an operation with or on this Geometry and its component Geometry's. Only GeometryCollections and Polygons have component Geometry's; for Polygons they are the LinearRings of the shell and holes.
-
clone
public Object clone()
Deprecated.Creates and returns a full copy of thisPolygonobject. (including all coordinates contained by it).
-
copyInternal
protected Polygon copyInternal()
Description copied from class:GeometryAn internal method to copy subclass-specific geometry data.- Specified by:
copyInternalin classGeometry- Returns:
- a copy of the target geometry object.
-
convexHull
public Geometry convexHull()
Description copied from class:GeometryComputes the smallest convexPolygonthat contains all the points in theGeometry. This obviously applies only toGeometrys which contain 3 or more points; the results for degenerate cases are specified as follows:Number of Points in argumentGeometryGeometryclass of result0 empty GeometryCollection1 Point2 LineString3 or more Polygon- Overrides:
convexHullin classGeometry- Returns:
- the minimum-area convex polygon containing this
Geometry' s points
-
normalize
public void normalize()
Description copied from class:GeometryConverts thisGeometryto normal form (or canonical form ). Normal form is a unique representation forGeometrys. It can be used to test whether twoGeometrys are equal in a way that is independent of the ordering of the coordinates within them. Normal form equality is a stronger condition than topological equality, but weaker than pointwise equality. The definitions for normal form use the standard lexicographical ordering for coordinates. "Sorted in order of coordinates" means the obvious extension of this ordering to sequences of coordinates.NOTE that this method mutates the value of this geometry in-place. If this is not safe and/or wanted, the geometry should be cloned prior to normalization.
-
compareToSameClass
protected int compareToSameClass(Object o)
Description copied from class:GeometryReturns whether thisGeometryis greater than, equal to, or less than anotherGeometryhaving the same class.- Specified by:
compareToSameClassin classGeometry- Parameters:
o- aGeometryhaving the same class as thisGeometry- Returns:
- a positive number, 0, or a negative number, depending on whether
this object is greater than, equal to, or less than
o, as defined in "Normal Form For Geometry" in the JTS Technical Specifications
-
compareToSameClass
protected int compareToSameClass(Object o, CoordinateSequenceComparator comp)
Description copied from class:GeometryReturns whether thisGeometryis greater than, equal to, or less than anotherGeometryof the same class. using the givenCoordinateSequenceComparator.- Specified by:
compareToSameClassin classGeometry- Parameters:
o- aGeometryhaving the same class as thisGeometrycomp- aCoordinateSequenceComparator- Returns:
- a positive number, 0, or a negative number, depending on whether
this object is greater than, equal to, or less than
o, as defined in "Normal Form For Geometry" in the JTS Technical Specifications
-
getSortIndex
protected int getSortIndex()
- Specified by:
getSortIndexin classGeometry
-
-