com.vividsolutions.jts.geom

Class Geometry

Implemented Interfaces:
Cloneable, Comparable, Serializable
Known Direct Subclasses:
GeometryCollection, LineString, Point, Polygon

public abstract class Geometry
extends java.lang.Object
implements Cloneable, Comparable, Serializable

The base class for all geometric objects.

Binary Predicates

Because it is not clear at this time what semantics for spatial analysis methods involving GeometryCollections would be useful, GeometryCollections are not supported as arguments to binary predicates (other than convexHull) or the relate method.

Set-Theoretic Methods

The spatial analysis methods will return the most specific class possible to represent the result. If the result is homogeneous, a Point, LineString, or Polygon will be returned if the result contains a single element; otherwise, a MultiPoint, MultiLineString, or MultiPolygon will be returned. If the result is heterogeneous a GeometryCollection will be returned.

Because it is not clear at this time what semantics for set-theoretic methods involving GeometryCollections would be useful, GeometryCollections are not supported as arguments to the set-theoretic methods.

Representation of Computed Geometries

The SFS states that the result of a set-theoretic method is the "point-set" result of the usual set-theoretic definition of the operation (SFS 3.2.21.1). However, there are sometimes many ways of representing a point set as a Geometry.

The SFS does not specify an unambiguous representation of a given point set returned from a spatial analysis method. One goal of JTS is to make this specification precise and unambiguous. JTS will use a canonical form for Geometrys returned from spatial analysis methods. The canonical form is a Geometry which is simple and noded:

This definition implies that non-simple geometries which are arguments to spatial analysis methods must be subjected to a line-dissolve process to ensure that the results are simple.

Constructed Points And The Precision Model

The results computed by the set-theoretic methods may contain constructed points which are not present in the input Geometry s. These new points arise from intersections between line segments in the edges of the input Geometrys. In the general case it is not possible to represent constructed points exactly. This is due to the fact that the coordinates of an intersection point may contain twice as many bits of precision as the coordinates of the input line segments. In order to represent these constructed points explicitly, JTS must truncate them to fit the PrecisionModel.

Unfortunately, truncating coordinates moves them slightly. Line segments which would not be coincident in the exact result may become coincident in the truncated representation. This in turn leads to "topology collapses" -- situations where a computed element has a lower dimension than it would in the exact result.

When JTS detects topology collapses during the computation of spatial analysis methods, it will throw an exception. If possible the exception will report the location of the collapse.

#equals(Object) and #hashCode are not overridden, so that when two topologically equal Geometries are added to HashMaps and HashSets, they remain distinct. This behaviour is desired in many cases.

Version:
1.7

Field Summary

protected int
SRID
The ID of the Spatial Reference System used by this Geometry
protected Envelope
envelope
The bounding box of this Geometry.

Constructor Summary

Geometry(GeometryFactory factory)

Method Summary

abstract void
apply(CoordinateFilter filter)
Performs an operation with or on this Geometry's coordinates.
abstract void
apply(GeometryComponentFilter filter)
Performs an operation with or on this Geometry and its component Geometry's.
abstract void
apply(GeometryFilter filter)
Performs an operation with or on this Geometry and its subelement Geometrys (if any).
Geometry
buffer(double distance)
Computes a buffer area around this geometry having the given width.
Geometry
buffer(double distance, int quadrantSegments)
Computes a buffer area around this geometry having the given width and with a specified accuracy of approximation for circular arcs.
Geometry
buffer(double distance, int quadrantSegments, int endCapStyle)
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.
protected void
checkNotGeometryCollection(Geometry g)
Throws an exception if g's class is GeometryCollection .
Object
clone()
protected int
compare(Collection a, Collection b)
Returns the first non-zero result of compareTo encountered as the two Collections are iterated over.
int
compareTo(Object o)
Returns whether this Geometry is greater than, equal to, or less than another Geometry.
int
compareTo(Object o, CoordinateSequenceComparator comp)
Returns whether this Geometry is greater than, equal to, or less than another Geometry, using the given CoordinateSequenceComparator.
protected abstract int
compareToSameClass(Object o)
Returns whether this Geometry is greater than, equal to, or less than another Geometry having the same class.
protected abstract int
compareToSameClass(Object o, CoordinateSequenceComparator comp)
Returns whether this Geometry is greater than, equal to, or less than another Geometry of the same class.
protected abstract Envelope
computeEnvelopeInternal()
Returns the minimum and maximum x and y values in this Geometry , or a null Envelope if this Geometry is empty.
boolean
contains(Geometry g)
Returns true if this geometry contains the specified geometry.
Geometry
convexHull()
Computes the smallest convex Polygon that contains all the points in the Geometry.
boolean
coveredBy(Geometry g)
Returns true if this geometry is covered by the specified geometry.
boolean
covers(Geometry g)
Returns true if this geometry covers the specified geometry.
boolean
crosses(Geometry g)
Returns true if this geometry crosses the specified geometry.
Geometry
difference(Geometry other)
Computes a Geometry representing the points making up this Geometry that do not make up other.
boolean
disjoint(Geometry g)
Returns true if this geometry is disjoint to the specified geometry.
double
distance(Geometry g)
Returns the minimum distance between this Geometry and the Geometry g
protected boolean
equal(Coordinate a, Coordinate b, double tolerance)
boolean
equals(Geometry g)
Returns true if this geometry is equal to the specified geometry.
boolean
equalsExact(Geometry other)
Returns true if the two Geometrys are exactly equal.
abstract boolean
equalsExact(Geometry other, double tolerance)
Returns true if the two Geometrys are exactly equal, up to a specified distance tolerance.
void
geometryChanged()
Notifies this Geometry that its Coordinates have been changed by an external party (using a CoordinateFilter, for example).
protected void
geometryChangedAction()
Notifies this Geometry that its Coordinates have been changed by an external party.
double
getArea()
Returns the area of this Geometry.
abstract Geometry
getBoundary()
Returns the boundary, or the empty geometry if this Geometry is empty.
abstract int
getBoundaryDimension()
Returns the dimension of this Geometrys inherent boundary.
Point
getCentroid()
Computes the centroid of this Geometry.
abstract Coordinate
getCoordinate()
Returns a vertex of this Geometry.
abstract Coordinate[]
getCoordinates()
Returns this Geometry s vertices.
abstract int
getDimension()
Returns the dimension of this Geometry.
Geometry
getEnvelope()
Returns this Geometrys bounding box.
Envelope
getEnvelopeInternal()
Returns the minimum and maximum x and y values in this Geometry , or a null Envelope if this Geometry is empty.
GeometryFactory
getFactory()
Gets the factory which contains the context in which this geometry was created.
Geometry
getGeometryN(int n)
Returns an element Geometry from a GeometryCollection (or this, if the geometry is not a collection).
abstract String
getGeometryType()
Returns the name of this object's com.vivid.jts.geom interface.
Point
getInteriorPoint()
Computes an interior point of this Geometry.
double
getLength()
Returns the length of this Geometry.
int
getNumGeometries()
Returns the number of Geometrys in a GeometryCollection (or 1, if the geometry is not a collection).
abstract int
getNumPoints()
Returns the count of this Geometrys vertices.
PrecisionModel
getPrecisionModel()
Returns the PrecisionModel used by the Geometry.
int
getSRID()
Returns the ID of the Spatial Reference System used by the Geometry.
Object
getUserData()
Gets the user data object for this geometry, if any.
protected static boolean
hasNonEmptyElements(Geometry[] geometries)
Returns true if the array contains any non-empty Geometrys.
protected static boolean
hasNullElements(Object[] array)
Returns true if the array contains any null elements.
Geometry
intersection(Geometry other)
Computes a Geometry representing the points shared by this Geometry and other.
boolean
intersects(Geometry g)
Returns true if this geometry intersects the specified geometry.
abstract boolean
isEmpty()
Returns whether or not the set of points in this Geometry is empty.
protected boolean
isEquivalentClass(Geometry other)
Returns whether the two Geometrys are equal, from the point of view of the equalsExact method.
boolean
isRectangle()
abstract boolean
isSimple()
Tests whether this Geometry is simple.
boolean
isValid()
Tests the validity of this Geometry.
boolean
isWithinDistance(Geometry geom, double distance)
Tests whether the distance from this Geometry to another is less than or equal to a specified value.
abstract void
normalize()
Converts this Geometry to normal form (or canonical form ).
boolean
overlaps(Geometry g)
Returns true if this geometry overlaps the specified geometry.
IntersectionMatrix
relate(Geometry g)
Returns the DE-9IM IntersectionMatrix for the two Geometrys.
boolean
relate(Geometry g, String intersectionPattern)
Returns true if the elements in the DE-9IM IntersectionMatrix for the two Geometrys match the elements in intersectionPattern.
void
setSRID(int SRID)
Sets the ID of the Spatial Reference System used by the Geometry.
void
setUserData(Object userData)
A simple scheme for applications to add their own custom data to a Geometry.
Geometry
symDifference(Geometry other)
Returns a set combining the points in this Geometry not in other, and the points in other not in this Geometry.
String
toString()
String
toText()
Returns the Well-known Text representation of this Geometry.
boolean
touches(Geometry g)
Returns true if this geometry touches the specified geometry.
Geometry
union(Geometry other)
Computes a Geometry representing all the points in this Geometry and other.
boolean
within(Geometry g)
Returns true if this geometry is within the specified geometry.

Field Details

SRID

protected int SRID
The ID of the Spatial Reference System used by this Geometry

envelope

protected Envelope envelope
The bounding box of this Geometry.

Constructor Details

Geometry

public Geometry(GeometryFactory factory)

Method Details

apply

public abstract void apply(CoordinateFilter filter)
Performs an operation with or on this Geometry's coordinates. If you are using this method to modify the geometry, be sure to call #geometryChanged() afterwards. 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 Coordinates at all).
Parameters:
filter - the filter to apply to this Geometry's coordinates

apply

public abstract void apply(GeometryComponentFilter filter)
Performs 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.
Parameters:
filter - the filter to apply to this Geometry.

apply

public abstract void apply(GeometryFilter filter)
Performs an operation with or on this Geometry and its subelement Geometrys (if any). Only GeometryCollections and subclasses have subelement Geometry's.
Parameters:
filter - the filter to apply to this Geometry (and its children, if it is a GeometryCollection).

buffer

public Geometry buffer(double distance)
Computes a buffer area around this geometry having the given width. The buffer of a Geometry is the Minkowski sum or difference of the geometry with a disc of radius abs(distance). The buffer is constructed using 8 segments per quadrant to represent curves. The end cap style is CAP_ROUND.
Parameters:
distance - the width of the buffer (may be positive, negative or 0)
Returns:
an area geometry representing the buffer region

buffer

public Geometry buffer(double distance,
                       int quadrantSegments)
Computes a buffer area around this geometry having the given width and with a specified accuracy of approximation for circular arcs.

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

Parameters:
distance - the width of the buffer (may be positive, negative or 0)
quadrantSegments - the number of line segments used to represent a quadrant of a circle
Returns:
an area geometry representing the buffer region

buffer

public Geometry buffer(double distance,
                       int quadrantSegments,
                       int endCapStyle)
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.

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
Parameters:
distance - the width of the buffer (may be positive, negative or 0)
quadrantSegments - the number of line segments used to represent a quadrant of a circle
endCapStyle - the end cap style to use
Returns:
an area geometry representing the buffer region

checkNotGeometryCollection

protected void checkNotGeometryCollection(Geometry g)
Throws an exception if g's class is GeometryCollection . (Its subclasses do not trigger an exception).
Parameters:
g - the Geometry to check

clone

public Object clone()

compare

protected int compare(Collection a,
                      Collection b)
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:
a - a Collection of Comparables
b - a Collection of Comparables
Returns:
the first non-zero compareTo result, if any; otherwise, zero

compareTo

public int compareTo(Object o)
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:
o - a Geometry with which to compare this Geometry
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

compareTo

public int compareTo(Object o,
                     CoordinateSequenceComparator comp)
Returns whether this Geometry is greater than, equal to, or less than another Geometry, using the given CoordinateSequenceComparator.

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:
o - a Geometry with which to compare this Geometry
comp - a CoordinateSequenceComparator
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 abstract int compareToSameClass(Object o)
Returns whether this Geometry is greater than, equal to, or less than another Geometry having the same class.
Parameters:
o - a Geometry having the same class as this Geometry
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 abstract int compareToSameClass(Object o,
                                          CoordinateSequenceComparator comp)
Returns whether this Geometry is greater than, equal to, or less than another Geometry of the same class. using the given CoordinateSequenceComparator.
Parameters:
o - a Geometry having the same class as this Geometry
comp - a CoordinateSequenceComparator
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

protected abstract Envelope computeEnvelopeInternal()
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.
Returns:
this Geometrys bounding box; if the Geometry is empty, Envelope#isNull will return true

contains

public boolean contains(Geometry g)
Returns true if 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 is T*****FF*
  • g.within(this) (contains is the inverse of within)
An implication of the definition is that "Polygons do not contain their boundary". In other words, if a geometry G is a subset of the points in the boundary of a polygon P, P.contains(G) = false
Parameters:
g - the Geometry with which to compare this Geometry
Returns:
true if this Geometry contains g

convexHull

public Geometry convexHull()
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
Returns:
the minimum-area convex polygon containing this Geometry' s points

coveredBy

public boolean coveredBy(Geometry g)
Returns true if 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 is T*F**F*** or *TF**F*** or **FT*F*** or **F*TF***
  • g.covers(this) (coveredBy is the inverse of covers)
Note the difference between coveredBy and within - coveredBy is a more inclusive relation
Parameters:
g - the Geometry with which to compare this Geometry
Returns:
true if this Geometry is covered by g

covers

public boolean covers(Geometry g)
Returns true if 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 is T*****FF* or *T****FF* or ***T**FF* or ****T*FF*
  • g.coveredBy(this) (covers is the inverse of coverdBy)
Note the difference between covers and contains - covers is a more inclusive relation. 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:
g - the Geometry with which to compare this Geometry
Returns:
true if this Geometry covers g

crosses

public boolean crosses(Geometry g)
Returns true if 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 is
    • T*T****** (for P/L, P/A, and L/A situations)
    • T*****T** (for L/P, L/A, 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. This makes the relation symmetric.

    Parameters:
    g - the Geometry with which to compare this Geometry
    Returns:
    true if the two Geometrys cross.

    difference

    public Geometry difference(Geometry other)
    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:
    other - the Geometry with which to compute the difference
    Returns:
    the point set difference of this Geometry with other

    disjoint

    public boolean disjoint(Geometry g)
    Returns true if this geometry is disjoint to 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 is FF*FF****
    • ! g.intersects(this) (disjoint is the inverse of intersects)
    Parameters:
    g - the Geometry with which to compare this Geometry
    Returns:
    true if the two Geometrys are disjoint

    distance

    public double distance(Geometry g)
    Returns the minimum distance between this Geometry and the Geometry g
    Parameters:
    g - the Geometry from which to compute the distance

    equal

    protected boolean equal(Coordinate a,
                            Coordinate b,
                            double tolerance)

    equals

    public boolean equals(Geometry g)
    Returns true if this geometry is equal to the specified geometry.

    The 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 is T*F**FFF*
    Parameters:
    Returns:
    true if the two Geometrys are equal

    equalsExact

    public boolean equalsExact(Geometry other)
    Returns true if the two Geometrys are exactly equal. Two Geometries are exactly equal iff:
    • they have the same class
    • they have the same values of Coordinates in their internal Coordinate lists, in exactly the same order.
    If this and the other Geometrys are composites and any children are not Geometrys, returns false.

    This provides a stricter test of equality than equals.

    Parameters:
    other - the Geometry with which to compare this Geometry
    Returns:
    true if this and the other Geometry are of the same class and have equal internal data.

    equalsExact

    public abstract boolean equalsExact(Geometry other,
                                        double tolerance)
    Returns true if the two Geometrys 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 class
    • they have the same values for their vertices, within the given tolerance distance, in exactly the same order.
    If this and the other Geometrys are composites and any children are not Geometrys, returns false.
    Parameters:
    other - the Geometry with which to compare this Geometry
    Returns:
    true if this and the other Geometry are of the same class and have equal internal data.

    geometryChanged

    public void geometryChanged()

    geometryChangedAction

    protected void geometryChangedAction()
    Notifies this Geometry that its Coordinates have been changed by an external party. When #geometryChanged is called, this method will be called for this Geometry and its component Geometries.

    getArea

    public double getArea()
    Returns the area of this Geometry. Areal Geometries have a non-zero area. They override this function to compute the area. Others return 0.0
    Returns:
    the area of the Geometry

    getBoundary

    public abstract Geometry getBoundary()
    Returns the boundary, or the empty geometry if this Geometry is empty. For a discussion of this function, see the OpenGIS Simple Features Specification. As stated in SFS Section 2.1.13.1, "the boundary of a Geometry is a set of Geometries of the next lower dimension."
    Returns:
    the closure of the combinatorial boundary of this Geometry

    getBoundaryDimension

    public abstract int getBoundaryDimension()
    Returns the dimension of this Geometrys inherent boundary.
    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.

    getCentroid

    public Point 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)
    Returns:
    a Point which is the centroid of this Geometry

    getCoordinate

    public abstract Coordinate getCoordinate()
    Returns a vertex of this Geometry.
    Returns:
    a Coordinate which is a vertex of this Geometry. Returns null if this Geometry is empty

    getCoordinates

    public abstract Coordinate[] getCoordinates()
    Returns this Geometry s vertices. If you modify the coordinates in this array, be sure to call #geometryChanged afterwards. The Geometrys contained by composite Geometrys must be Geometry's; that is, they must implement getCoordinates.
    Returns:
    the vertices of this Geometry

    getDimension

    public abstract int getDimension()
    Returns the dimension of this Geometry.
    Returns:
    the dimension of the class implementing this interface, whether or not this object is the empty geometry

    getEnvelope

    public Geometry getEnvelope()
    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).
    Returns:
    an empty Point (for empty Geometrys), a Point (for Points) or a Polygon (in all other cases)

    getEnvelopeInternal

    public Envelope getEnvelopeInternal()
    Returns the minimum and maximum x and y values in this Geometry , or a null Envelope if this Geometry is empty.
    Returns:
    this Geometrys bounding box; if the Geometry is empty, Envelope#isNull will return true

    getFactory

    public GeometryFactory getFactory()
    Gets the factory which contains the context in which this geometry was created.
    Returns:
    the factory for this geometry

    getGeometryN

    public Geometry getGeometryN(int n)
    Returns an element Geometry from a GeometryCollection (or this, if the geometry is not a collection).
    Parameters:
    n - the index of the geometry element
    Returns:
    the n'th geometry contained in this geometry

    getGeometryType

    public abstract String getGeometryType()
    Returns the name of this object's com.vivid.jts.geom interface.
    Returns:
    the name of this Geometrys most specific com.vividsolutions.jts.geom interface

    getInteriorPoint

    public Point getInteriorPoint()
    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.
    Returns:
    a Point which is in the interior of this Geometry

    getLength

    public double getLength()
    Returns the length of this Geometry. Linear geometries return their length. Areal geometries return their perimeter. They override this function to compute the area. Others return 0.0
    Returns:
    the length of the Geometry

    getNumGeometries

    public int getNumGeometries()
    Returns the number of Geometrys in a GeometryCollection (or 1, if the geometry is not a collection).
    Returns:
    the number of geometries contained in this geometry

    getNumPoints

    public abstract int getNumPoints()
    Returns the count of this Geometrys vertices. The Geometry s contained by composite Geometrys must be Geometry's; that is, they must implement getNumPoints
    Returns:
    the number of vertices in this Geometry

    getPrecisionModel

    public PrecisionModel getPrecisionModel()
    Returns the PrecisionModel used by the Geometry.
    Returns:
    the specification of the grid of allowable points, for this Geometry and all other Geometrys

    getSRID

    public int getSRID()
    Returns the ID of the Spatial Reference System used by the Geometry.

    JTS supports Spatial Reference System information in the simple way defined in the SFS. A Spatial Reference System ID (SRID) is present in each Geometry object. Geometry provides basic accessor operations for this field, but no others. The SRID is represented as an integer.

    Returns:
    the ID of the coordinate space in which the Geometry is defined.

    getUserData

    public Object getUserData()
    Gets the user data object for this geometry, if any.
    Returns:
    the user data object, or null if none set

    hasNonEmptyElements

    protected static boolean hasNonEmptyElements(Geometry[] geometries)
    Returns true if the array contains any non-empty Geometrys.
    Parameters:
    geometries - an array of Geometrys; no elements may be null
    Returns:
    true if any of the Geometrys isEmpty methods return false

    hasNullElements

    protected static boolean hasNullElements(Object[] array)
    Returns true if the array contains any null elements.
    Parameters:
    array - an array to validate
    Returns:
    true if any of arrays elements are null

    intersection

    public Geometry intersection(Geometry other)
    Computes a Geometry representing the points shared by this Geometry and other.
    Parameters:
    other - the Geometry with which to compute the intersection
    Returns:
    the points common to the two Geometrys

    intersects

    public boolean intersects(Geometry g)
    Returns true if this geometry intersects the specified geometry.

    The intersects predicate has the following equivalent definitions:

    • The two geometries have at least one point in common
    • ! g.disjoint(this) (intersects is the inverse of disjoint)
    Parameters:
    g - the Geometry with which to compare this Geometry
    Returns:
    true if the two Geometrys intersect

    isEmpty

    public abstract boolean isEmpty()
    Returns whether or not the set of points in this Geometry is empty.
    Returns:
    true if this Geometry equals the empty geometry

    isEquivalentClass

    protected boolean isEquivalentClass(Geometry other)
    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:
    other - the Geometry with which to compare this Geometry for equality
    Returns:
    true if the classes of the two Geometry s are considered to be equal by the equalsExact method.

    isRectangle

    public boolean isRectangle()

    isSimple

    public abstract boolean isSimple()
    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
      Returns:
      true if this Geometry has any points of self-tangency, self-intersection or other anomalous points
      See Also:
      isValid()

      isValid

      public boolean isValid()
      Tests the validity of this Geometry. Subclasses provide their own definition of "valid".
      Returns:
      true if this Geometry is valid

      isWithinDistance

      public boolean isWithinDistance(Geometry geom,
                                      double distance)
      Tests whether the distance from this Geometry to another is less than or equal to a specified value.
      Parameters:
      geom - the Geometry to check the distance to
      distance - the distance value to compare
      Returns:
      true if the geometries are less than distance apart.

      normalize

      public abstract void 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.

      overlaps

      public boolean overlaps(Geometry g)
      Returns true if this geometry overlaps the specified geometry.

      The overlaps predicate has the following equivalent definitions:

      • The geometries have some but not all points in common, 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 is 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:
      g - the Geometry with which to compare this Geometry
      Returns:
      true if the two Geometrys overlap.

      relate

      public IntersectionMatrix relate(Geometry g)
      Returns the DE-9IM IntersectionMatrix for the two Geometrys.
      Parameters:
      Returns:
      an IntersectionMatrix describing the intersections of the interiors, boundaries and exteriors of the two Geometrys

      relate

      public boolean relate(Geometry g,
                            String intersectionPattern)
      Returns true if 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:
      intersectionPattern - the pattern against which to check the intersection matrix for the two Geometrys
      Returns:
      true if the DE-9IM intersection matrix for the two Geometrys match intersectionPattern

      setSRID

      public void setSRID(int SRID)
      Sets the ID of the Spatial Reference System used by the Geometry.

      setUserData

      public void setUserData(Object userData)
      A simple scheme for applications to add their own custom data to a Geometry. An example use might be to add an object representing a Coordinate Reference System.

      Note that user data objects are not present in geometries created by construction methods.

      Parameters:
      userData - an object, the semantics for which are defined by the application using this Geometry

      symDifference

      public Geometry symDifference(Geometry other)
      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:
      other - the Geometry with which to compute the symmetric difference
      Returns:
      the point set symmetric difference of this Geometry with other

      toString

      public String toString()

      toText

      public String toText()
      Returns the Well-known Text representation of this Geometry. For a definition of the Well-known Text format, see the OpenGIS Simple Features Specification.
      Returns:
      the Well-known Text representation of this Geometry

      touches

      public boolean touches(Geometry g)
      Returns true if 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 is FT*******, F**T***** or F***T****
      If both geometries have dimension 0, this predicate returns false
      Parameters:
      g - the Geometry with which to compare this Geometry
      Returns:
      true if the two Geometrys touch; Returns false if both Geometrys are points

      union

      public Geometry union(Geometry other)
      Computes a Geometry representing all the points in this Geometry and other.
      Parameters:
      other - the Geometry with which to compute the union
      Returns:
      a set combining the points of this Geometry and the points of other

      within

      public boolean within(Geometry g)
      Returns true if 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 is T*F**F***
      • g.contains(this) (within is the inverse of contains)
      An implication of the definition is that "The boundary of a Polygon is not within the Polygon". In other words, if a geometry G is a subset of the points in the boundary of a polygon P, G.within(P) = false
      Parameters:
      g - the Geometry with which to compare this Geometry
      Returns:
      true if this Geometry is within other