Class: Polygon

jsts.geom.Polygon

new Polygon()

Source:

Extends

Members

envelope

The bounding box of this Geometry.
Inherited From:
Source:

(protected) factory

The GeometryFactory used to create this Geometry
Overrides:
Source:

Methods

apply(filter)

Performs an operation with or on this Geometry and its subelement Geometrys (if any). Only GeometryCollections and subclasses have subelement Geometry's.
Parameters:
Name Type Description
filter the filter to apply to this Geometry (and its children, if it is a GeometryCollection).
Overrides:
Source:

buffer(distance, quadrantSegments, endCapStyle) → {Geometry}

Computes a buffer area around this geometry having the given width and with a specified accuracy of approximation for circular arcs, and using a specified end cap style.

Mathematically-exact buffer area boundaries can contain circular arcs. To represent these arcs using linear geometry they must be approximated with line segments. The quadrantSegments argument allows controlling the accuracy of the approximation by specifying the number of line segments used to represent a quadrant of a circle

The end cap style specifies the buffer geometry that will be created at the ends of linestrings. The styles provided are:

  • BufferOp.CAP_ROUND - (default) a semi-circle
  • BufferOp.CAP_BUTT - a straight line perpendicular to the end segment
  • BufferOp.CAP_SQUARE - a half-square

The buffer operation always returns a polygonal result. The negative or zero-distance buffer of lines and points is always an empty Polygon. This is also the result for the buffers of degenerate (zero-area) polygons.

Parameters:
Name Type Description
distance number the width of the buffer (may be positive, negative or 0).
quadrantSegments number the number of line segments used to represent a quadrant of a circle.
endCapStyle number the end cap style to use.
Inherited From:
Source:
See:
Throws:
TopologyException if a robustness error occurs
Returns:
a polygonal geometry representing the buffer region (which may be empty).
Type
Geometry

checkNotGeometryCollection(g)

Throws an exception if g's class is GeometryCollection . (Its subclasses do not trigger an exception).
Parameters:
Name Type Description
g Geometry the Geometry to check.
Inherited From:
Source:
Throws:
Error if g is a GeometryCollection but not one of its subclasses

clone()

Creates and returns a full copy of this Polygon object. (including all coordinates contained by it).
Overrides:
Source:
Returns:
a clone of this instance.

compare(a, b) → {number}

Returns the first non-zero result of compareTo encountered as the two Collections are iterated over. If, by the time one of the iterations is complete, no non-zero result has been encountered, returns 0 if the other iteration is also complete. If b completes before a, a positive number is returned; if a before b, a negative number.
Parameters:
Name Type Description
a Array a Collection of Comparables.
b Array a Collection of Comparables.
Inherited From:
Source:
Returns:
the first non-zero compareTo result, if any; otherwise, zero.
Type
number

compareTo(other) → {number}

Returns whether this Geometry is greater than, equal to, or less than another Geometry.

If their classes are different, they are compared using the following ordering:

  • Point (lowest)
  • MultiPoint
  • LineString
  • LinearRing
  • MultiLineString
  • Polygon
  • MultiPolygon
  • GeometryCollection (highest)
If the two Geometrys have the same class, their first elements are compared. If those are the same, the second elements are compared, etc.
Parameters:
Name Type Description
other Geometry a Geometry with which to compare this Geometry.
Inherited From:
Source:
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.
Type
number

compareToSameClass(o)

Returns whether this Geometry is greater than, equal to, or less than another Geometry having the same class.
Parameters:
Name Type Description
o a Geometry having the same class as this Geometry.
Overrides:
Source:
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.

computeEnvelopeInternal() → {Envelope}

Returns the minimum and maximum x and y values in this Geometry, or a null Envelope if this Geometry is empty. Unlike getEnvelopeInternal, this method calculates the Envelope each time it is called; getEnvelopeInternal caches the result of this method.
Overrides:
Source:
Returns:
this Geometrys bounding box; if the Geometry is empty, Envelope#isNull will return true.
Type
Envelope

contains(g) → {boolean}

Tests whether this geometry contains the specified geometry.

The contains predicate has the following equivalent definitions:

  • Every point of the other geometry is a point of this geometry, and the interiors of the two geometries have at least one point in common.
  • The DE-9IM Intersection Matrix for the two geometries matches [T*****FF*]
  • g.within(this) (contains is the converse of within)
An implication of the definition is that "Geometries do not contain their boundary". In other words, if a geometry A is a subset of the points in the boundary of a geometry B, B.contains(A) = false
Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
See:
  • Geometry#within
Returns:
true if this Geometry contains g.
Type
boolean

convexHull() → {Geometry}

Computes the smallest convex Polygon that contains all the points in the Geometry. This obviously applies only to Geometry s which contain 3 or more points; the results for degenerate cases are specified as follows:
Number of Points in argument Geometry Geometry class of result
0 empty GeometryCollection
1 Point
2 LineString
3 or more Polygon
Inherited From:
Source:
Returns:
the minimum-area convex polygon containing this Geometry' s points.
Type
Geometry

coveredBy(g) → {boolean}

Tests whether this geometry is covered by the specified geometry.

The coveredBy predicate has the following equivalent definitions:

  • Every point of this geometry is a point of the other geometry.
  • The DE-9IM Intersection Matrix for the two geometries matches [T*F**F***] or [*TF**F***] or [**FT*F***] or [**F*TF***]
  • g.covers(this) (coveredBy is the converse of covers)
If either geometry is empty, the value of this predicate is false.

This predicate is similar to #within, but is more inclusive (i.e. returns true for more cases).

Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
See:
  • Geometry#within
  • Geometry#covers
Returns:
true if this Geometry is covered by g.
Type
boolean

covers(g) → {boolean}

Tests whether this geometry covers the specified geometry.

The covers predicate has the following equivalent definitions:

  • Every point of the other geometry is a point of this geometry.
  • The DE-9IM Intersection Matrix for the two geometries matches [T*****FF*] or [*T****FF*] or [***T**FF*] or [****T*FF*]
  • g.coveredBy(this) (covers is the converse of coveredBy)
If either geometry is empty, the value of this predicate is false.

This predicate is similar to #contains, but is more inclusive (i.e. returns true for more cases). In particular, unlike contains it does not distinguish between points in the boundary and in the interior of geometries. For most situations, covers should be used in preference to contains. As an added benefit, covers is more amenable to optimization, and hence should be more performant.

Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
See:
  • Geometry#contains
  • Geometry#coveredBy
Returns:
true if this Geometry covers g.
Type
boolean

crosses(g) → {boolean}

Tests whether this geometry crosses the specified geometry.

The crosses predicate has the following equivalent definitions:

  • The geometries have some but not all interior points in common.
  • The DE-9IM Intersection Matrix for the two geometries matches
    • [T*T******] (for P/L, P/A, and L/A situations)
    • [T*****T**] (for L/P, A/P, and A/L situations)
    • [0********] (for L/L situations)
For any other combination of dimensions this predicate returns false.

The SFS defined this predicate only for P/L, P/A, L/L, and L/A situations. JTS extends the definition to apply to L/P, A/P and A/L situations as well, in order to make the relation symmetric.

Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
Returns:
true if the two Geometrys cross.
Type
boolean

difference(other) → {Geometry}

Computes a Geometry representing the points making up this Geometry that do not make up other. This method returns the closure of the resultant Geometry.
Parameters:
Name Type Description
other Geometry the Geometry with which to compute the difference.
Inherited From:
Source:
Throws:
  • TopologyException if a robustness error occurs
  • IllegalArgumentException if either input is a non-empty GeometryCollection
Returns:
the point set difference of this Geometry with other.
Type
Geometry

disjoint(g) → {boolean}

Tests whether this geometry is disjoint from the specified geometry.

The disjoint predicate has the following equivalent definitions:

  • The two geometries have no point in common
  • The DE-9IM Intersection Matrix for the two geometries matches [FF*FF****]
  • ! g.intersects(this) (disjoint is the inverse of intersects)
Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
See:
  • Geometry#intersects
Returns:
true if the two Geometrys are disjoint.
Type
boolean

distance(g) → {number}

Returns the minimum distance between this Geometry and the Geometry g
Parameters:
Name Type Description
g Geometry the Geometry from which to compute the distance.
Inherited From:
Source:
Throws:
IllegalArgumentException if g is null
Returns:
the distance between the geometries. 0 if either input geometry is empty.
Type
number

equal(a, b, tolerance) → {boolean}

Parameters:
Name Type Description
a jsts.geom.Coordinate first Coordinate to compare.
b jsts.geom.Coordinate second Coordinate to compare.
tolerance number tolerance when comparing.
Inherited From:
Source:
Returns:
true if equal.
Type
boolean

equals(o) → {boolean}

Tests whether this geometry is structurally and numerically equal to a given Object. If the argument Object is not a Geometry, the result is false. Otherwise, the result is computed using #equalsExact(Geometry).

This method is provided to fulfill the Java contract for value-based object equality. In conjunction with #hashCode() it provides semantics which are most useful for using Geometrys as keys and values in Java collections.

Note that to produce the expected result the input geometries should be in normal form. It is the caller's responsibility to perform this where required (using or as appropriate).

Parameters:
Name Type Description
o Object the Object to compare.
Inherited From:
Source:
See:
Returns:
true if this geometry is exactly equal to the argument.
Type
boolean

equalsExact(other, tolerance) → {boolean

Parameters:
Name Type Description
other Geometry
tolerance number
Overrides:
Source:
Returns:
Type
boolean

equalsNorm(g) → {boolean}

Tests whether two geometries are exactly equal in their normalized forms. This is a convenience method which creates normalized versions of both geometries before computing #equalsExact(Geometry). This method is relatively expensive to compute. For maximum performance, the client should instead perform normalization itself at an appropriate point during execution.
Parameters:
Name Type Description
g Geometry a Geometry.
Inherited From:
Source:
Returns:
true if the input geometries are exactly equal in their normalized form.
Type
boolean

equalsTopo(g) → {boolean}

Tests whether this geometry is topologically equal to the argument geometry as defined by the SFS equals predicate.

The SFS equals predicate has the following equivalent definitions:

  • The two geometries have at least one point in common, and no point of either geometry lies in the exterior of the other geometry.
  • The DE-9IM Intersection Matrix for the two geometries matches the pattern T*F**FFF*
    T*F
    **F
    FF*
    
Note that this method computes topologically equality. For structural equality, see #equalsExact(Geometry).
Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
See:
Returns:
true if the two Geometrys are topologically equal.
Type
boolean

getArea()

Returns the area of this Polygon
Overrides:
Source:
Returns:
the area of the polygon.

getBoundary() → {Geometry}

Computes the boundary of this geometry
Overrides:
Source:
See:
  • Geometry#getBoundary
Returns:
a lineal geometry (which may be empty).
Type
Geometry

getBoundaryDimension() → {number}

Returns the dimension of this Geometrys inherent boundary.
Overrides:
Source:
Returns:
the dimension of the boundary of the class implementing this interface, whether or not this object is the empty geometry. Returns Dimension.FALSE if the boundary is the empty geometry.
Type
number

getCentroid()

Computes the centroid of this Geometry. The centroid is equal to the centroid of the set of component Geometries of highest dimension (since the lower-dimension geometries contribute zero "weight" to the centroid)
Inherited From:
Source:
Returns:
a Point which is the centroid of this Geometry.

getCoordinate() → {Coordinate}

Returns a vertex of this Geometry (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.
Overrides:
Source:
Returns:
a Coordinate which is a vertex of this Geometry. null if this Geometry is empty.
Type
Coordinate

getCoordinates() → {Array.<Coordinate>}

Returns 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 method (possibly on the components) to modify the underlying data. If the coordinates are modified, #geometryChanged must be called afterwards.

Overrides:
Source:
See:
  • geometryChanged
  • CoordinateSequence#setOrdinate
Returns:
the vertices of this Geometry.
Type
Array.<Coordinate>

getDimension() → {number}

Returns 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).

Overrides:
Source:
Returns:
the topological dimension of this geometry.
Type
number

getEnvelope() → {Geometry}

Returns this Geometrys bounding box. If this Geometry is the empty geometry, returns an empty Point. If the Geometry is a point, returns a non-empty Point. Otherwise, returns a Polygon whose points are (minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy), (minx, miny).
Inherited From:
Source:
Returns:
an empty Point (for empty Geometrys), a Point (for Points) or a Polygon (in all other cases).
Type
Geometry

getEnvelopeInternal() → {Envelope}

Returns the minimum and maximum x and y values in this Geometry, or a null Envelope if this Geometry is empty.
Inherited From:
Source:
Returns:
this Geometrys bounding box; if the Geometry is empty, Envelope#isNull will return true.
Type
Envelope

getFactory() → {jsts.geom.GeometryFactory}

Gets the factory which contains the context in which this geometry was created.
Inherited From:
Source:
Returns:
the factory for this geometry.
Type
jsts.geom.GeometryFactory

getGeometryN(n) → {Geometry}

Returns an element Geometry from a GeometryCollection (or this, if the geometry is not a collection).
Parameters:
Name Type Description
n number the index of the geometry element.
Inherited From:
Source:
Returns:
the n'th geometry contained in this geometry.
Type
Geometry

getGeometryType() → {String}

Overrides:
Source:
Returns:
String representation of Polygon type.
Type
String

getInteriorPoint() → {Point}

Computes an interior point of this Geometry. An interior point is guaranteed to lie in the interior of the Geometry, if it possible to calculate such a point exactly. Otherwise, the point may lie on the boundary of the geometry.
Inherited From:
Source:
Returns:
a Point which is in the interior of this Geometry.
Type
Point

getLength()

Returns the perimeter of this Polygon
Overrides:
Source:
Returns:
the perimeter of the polygon.

getNumGeometries() → {number}

Returns the number of Geometrys in a GeometryCollection (or 1, if the geometry is not a collection).
Inherited From:
Source:
Returns:
the number of geometries contained in this geometry.
Type
number

getNumPoints() → {number}

Overrides:
Source:
Returns:
Type
number

getPrecisionModel() → {PrecisionModel}

Returns the PrecisionModel used by the Geometry.
Inherited From:
Source:
Returns:
the specification of the grid of allowable points, for this Geometry and all other Geometrys.
Type
PrecisionModel

intersection(other) → {Geometry}

Computes a Geometry representing the points shared by this Geometry and other. GeometryCollections support intersection with homogeneous collection types, with the semantics that the result is a GeometryCollection of the intersection of each element of the target with the argument.
Parameters:
Name Type Description
other Geometry the Geometry with which to compute the intersection.
Inherited From:
Source:
Throws:
  • TopologyException if a robustness error occurs
  • IllegalArgumentException if the argument is a non-empty GeometryCollection
Returns:
the points common to the two Geometrys.
Type
Geometry

intersects(g) → {boolean}

Tests whether this geometry intersects the specified geometry.

The intersects predicate has the following equivalent definitions:

  • The two geometries have at least one point in common
  • The DE-9IM Intersection Matrix for the two geometries matches [T********] or [*T*******] or [***T*****] or [****T****]
  • ! g.disjoint(this) (intersects is the inverse of disjoint)
Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
See:
  • Geometry#disjoint
Returns:
true if the two Geometrys intersect.
Type
boolean

isEmpty() → {boolean}

Overrides:
Source:
Returns:
Type
boolean

isEquivalentClass(other) → {boolean}

Returns whether the two Geometrys are equal, from the point of view of the equalsExact method. Called by equalsExact . In general, two Geometry classes are considered to be "equivalent" only if they are the same class. An exception is LineString , which is considered to be equivalent to its subclasses.
Parameters:
Name Type Description
other Geometry the Geometry with which to compare this Geometry for equality.
Inherited From:
Source:
Returns:
true if the classes of the two Geometry s are considered to be equal by the equalsExact method.
Type
boolean

isGeometryCollection() → {boolean}

Inherited From:
Source:
Returns:
true if this is a GeometryCollection.
Type
boolean

isGeometryCollectionBase() → {boolean}

Inherited From:
Source:
Returns:
true if this is a GeometryCollection but not subclass.
Type
boolean

isSimple() → {boolean}

Tests whether this Geometry is simple. In general, the SFS specification of simplicity follows the rule:
  • A Geometry is simple iff the only self-intersections are at boundary points.
Simplicity is defined for each Geometry subclass as follows:
  • Valid polygonal geometries are simple by definition, so isSimple trivially returns true.
  • Linear geometries are simple iff they do not self-intersect at points other than boundary points.
  • Zero-dimensional geometries (points) are simple iff they have no repeated points.
  • Empty Geometrys are always simple
Inherited From:
Source:
See:
Returns:
true if this Geometry has any points of self-tangency, self-intersection or other anomalous points.
Type
boolean

isValid() → {boolean}

Tests the validity of this Geometry. Subclasses provide their own definition of "valid".
Inherited From:
Source:
See:
  • IsValidOp
Returns:
true if this Geometry is valid.
Type
boolean

isWithinDistance(geom, distance) → {boolean}

Tests whether the distance from this Geometry to another is less than or equal to a specified value.
Parameters:
Name Type Description
geom Geometry the Geometry to check the distance to.
distance number the distance value to compare.
Inherited From:
Source:
Returns:
true if the geometries are less than distance apart.
Type
boolean

norm()

Creates a new Geometry which is a normalized copy of this Geometry.
Inherited From:
Source:
See:
Returns:
a normalized copy of this geometry.

normalize()

Converts this Geometry to normal form (or canonical form ). Normal form is a unique representation for Geometry s. It can be used to test whether two Geometrys 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.
Overrides:
Source:

overlaps(g) → {boolean}

Tests whether this geometry overlaps the specified geometry.

The overlaps predicate has the following equivalent definitions:

  • The geometries have at least one point each not shared by the other (or equivalently neither covers the other), they have the same dimension, and the intersection of the interiors of the two geometries has the same dimension as the geometries themselves.
  • The DE-9IM Intersection Matrix for the two geometries matches [T*T***T**] (for two points or two surfaces) or [1*T***T**] (for two curves)
If the geometries are of different dimension this predicate returns false.
Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
Returns:
true if the two Geometrys overlap.
Type
boolean

relate(other, intersectionPattern) → {boolean}

Tests whether the elements in the DE-9IM IntersectionMatrix for the two Geometrys match the elements in intersectionPattern. The pattern is a 9-character string, with symbols drawn from the following set:
  • 0 (dimension 0)
  • 1 (dimension 1)
  • 2 (dimension 2)
  • T ( matches 0, 1 or 2)
  • F ( matches FALSE)
  • * ( matches any value)
For more information on the DE-9IM, see the OpenGIS Simple Features Specification.
Parameters:
Name Type Description
other Geometry the Geometry with which to compare this Geometry.
intersectionPattern string the pattern against which to check the intersection matrix for the two Geometrys.
Inherited From:
Source:
See:
  • IntersectionMatrix
Returns:
true if the DE-9IM intersection matrix for the two Geometrys match intersectionPattern.
Type
boolean

relate2(g) → {IntersectionMatrix}

Returns the DE-9IM IntersectionMatrix for the two Geometrys.
Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
Returns:
an IntersectionMatrix describing the intersections of the interiors, boundaries and exteriors of the two Geometrys.
Type
IntersectionMatrix

symDifference(other) → {Geometry}

Returns a set combining the points in this Geometry not in other, and the points in other not in this Geometry. This method returns the closure of the resultant Geometry.
Parameters:
Name Type Description
other Geometry the Geometry with which to compute the symmetric difference.
Inherited From:
Source:
Throws:
  • TopologyException if a robustness error occurs
  • IllegalArgumentException if either input is a non-empty GeometryCollection
Returns:
the point set symmetric difference of this Geometry with other.
Type
Geometry

touches(g) → {boolean}

Tests whether this geometry touches the specified geometry.

The touches predicate has the following equivalent definitions:

  • The geometries have at least one point in common, but their interiors do not intersect.
  • The DE-9IM Intersection Matrix for the two geometries matches [FT*******] or [F**T*****] or [F***T****]
If both geometries have dimension 0, this predicate returns false
Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
Returns:
true if the two Geometrys touch; Returns false if both Geometrys are points.
Type
boolean

union(other) → {Geometry}

Computes a Geometry representing all the points in this Geometry and other. Or without arguments: Computes the union of all the elements of this geometry. Heterogeneous GeometryCollections are fully supported. The result obeys the following contract:
  • Unioning a set of LineStrings has the effect of fully noding and dissolving the linework.
  • Unioning a set of Polygons will always return a Polygonal geometry (unlike {link #union(Geometry)}, which may return geometrys of lower dimension if a topology collapse occurred.
Parameters:
Name Type Description
other Geometry the Geometry with which to compute the union.
Inherited From:
Source:
Throws:
  • TopologyException if a robustness error occurs
  • IllegalArgumentException if either input is a non-empty GeometryCollection
Returns:
a set combining the points of this Geometry and the points of other.
Type
Geometry

within(g) → {boolean}

Tests whether this geometry is within the specified geometry.

The within predicate has the following equivalent definitions:

  • Every point of this geometry is a point of the other geometry, and the interiors of the two geometries have at least one point in common.
  • The DE-9IM Intersection Matrix for the two geometries matches [T*F**F***]
  • g.contains(this) (within is the converse of contains)
An implication of the definition is that "The boundary of a Geometry is not within the Geometry". In other words, if a geometry A is a subset of the points in the boundary of a geomtry B, A.within(B) = false
Parameters:
Name Type Description
g Geometry the Geometry with which to compare this Geometry.
Inherited From:
Source:
See:
  • Geometry#contains
Returns:
true if this Geometry is within other.
Type
boolean