com.vividsolutions.jts.geom
Class Geometry

java.lang.Object
  extended bycom.vividsolutions.jts.geom.Geometry
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable
Direct Known Subclasses:
GeometryCollection, LineString, Point, Polygon

public abstract class Geometry
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable, java.io.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
See Also:
Serialized Form

Field Summary
protected  Envelope envelope
          The bounding box of this Geometry.
protected  GeometryFactory factory
          The GeometryFactory used to create this Geometry
protected  int SRID
          The ID of the Spatial Reference System used by this Geometry
 
Constructor Summary
Geometry(GeometryFactory factory)
          Creates a new Geometry via the specified GeometryFactory.
 
Method Summary
abstract  void apply(CoordinateFilter filter)
          Performs an operation with or on this Geometry's coordinates.
abstract  void apply(CoordinateSequenceFilter filter)
          Performs an operation on the coordinates in this Geometry's CoordinateSequences.
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 .
 java.lang.Object clone()
          Creates and returns a full copy of this Geometry object (including all coordinates contained by it).
protected  int compare(java.util.Collection a, java.util.Collection b)
          Returns the first non-zero result of compareTo encountered as the two Collections are iterated over.
 int compareTo(java.lang.Object o)
          Returns whether this Geometry is greater than, equal to, or less than another Geometry.
 int compareTo(java.lang.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(java.lang.Object o)
          Returns whether this Geometry is greater than, equal to, or less than another Geometry having the same class.
protected abstract  int compareToSameClass(java.lang.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 an empty geometry of appropriate dimension 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  java.lang.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.
 java.lang.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(java.lang.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()
           
 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, java.lang.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(java.lang.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.
 java.lang.String toString()
           
 java.lang.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.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

envelope

protected Envelope envelope
The bounding box of this Geometry.


factory

protected final GeometryFactory factory
The GeometryFactory used to create this Geometry


SRID

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

Constructor Detail

Geometry

public Geometry(GeometryFactory factory)
Creates a new Geometry via the specified GeometryFactory.

Parameters:
factory -
Method Detail

getGeometryType

public abstract java.lang.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

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(java.lang.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

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.

setSRID

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


getFactory

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

Returns:
the factory for this geometry

getUserData

public java.lang.Object getUserData()
Gets the user data object for this geometry, if any.

Returns:
the user data object, or null if none set

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

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

setUserData

public void setUserData(java.lang.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

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

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

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

isSimple

public boolean isSimple()
Tests whether this Geometry is simple. In general, the SFS specification of simplicity follows the rule: Simplicity is defined for each Geometry subclass as follows:

isValid

public boolean isValid()
Tests the validity of this Geometry. Subclasses provide their own definition of "valid".

Returns:
true if this Geometry is valid
See Also:
IsValidOp

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

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

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.

isRectangle

public boolean isRectangle()

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

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

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

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

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

getBoundary

public abstract Geometry getBoundary()
Returns the boundary, or an empty geometry of appropriate dimension if this Geometry is empty. (In the case of zero-dimensional geometries, ' an empty GeometryCollection is returned.) 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.

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

geometryChanged

public void geometryChanged()
Notifies this Geometry that its Coordinates have been changed by an external party (using a CoordinateFilter, for example). The Geometry will flush and/or update any information it has cached (such as its Envelope ).


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.

See Also:
apply(GeometryComponentFilter)

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:

Parameters:
g - the Geometry with which to compare this Geometry
Returns:
true if the two Geometrys are disjoint
See Also:
intersects(com.vividsolutions.jts.geom.Geometry)

touches

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

The touches predicate has the following equivalent definitions:

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

intersects

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

The intersects predicate has the following equivalent definitions:

Parameters:
g - the Geometry with which to compare this Geometry
Returns:
true if the two Geometrys intersect
See Also:
disjoint(com.vividsolutions.jts.geom.Geometry)

crosses

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

The crosses predicate has the following equivalent definitions:

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.

within

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

The within predicate has the following equivalent definitions:

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
See Also:
contains(com.vividsolutions.jts.geom.Geometry)

contains

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

The contains predicate has the following equivalent definitions:

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
See Also:
within(com.vividsolutions.jts.geom.Geometry)

overlaps

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

The overlaps predicate has the following equivalent definitions:

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.

covers

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

The covers predicate has the following equivalent definitions:

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
See Also:
contains(com.vividsolutions.jts.geom.Geometry), coveredBy(com.vividsolutions.jts.geom.Geometry)

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:

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
See Also:
within(com.vividsolutions.jts.geom.Geometry), covers(com.vividsolutions.jts.geom.Geometry)

relate

public boolean relate(Geometry g,
                      java.lang.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: 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
See Also:
IntersectionMatrix

relate

public IntersectionMatrix relate(Geometry g)
Returns the DE-9IM IntersectionMatrix for the two Geometrys.

Returns:
an IntersectionMatrix describing the intersections of the interiors, boundaries and exteriors of the two Geometrys

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:

Returns:
true if the two Geometrys are equal

toString

public java.lang.String toString()

toText

public java.lang.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

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
Throws:
TopologyException - if a robustness error occurs
See Also:
buffer(double, int), buffer(double, int, int)

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
Throws:
TopologyException - if a robustness error occurs
See Also:
buffer(double), buffer(double, int, int)

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:

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
Throws:
TopologyException - if a robustness error occurs
See Also:
buffer(double), buffer(double, int), BufferOp

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

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
Throws:
TopologyException - if a robustness error occurs
java.lang.IllegalArgumentException - if either input is a non-empty GeometryCollection

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
Throws:
TopologyException - if a robustness error occurs
java.lang.IllegalArgumentException - if either input is a non-empty GeometryCollection

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
Throws:
TopologyException - if a robustness error occurs
java.lang.IllegalArgumentException - if either input is a non-empty GeometryCollection

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
Throws:
TopologyException - if a robustness error occurs
java.lang.IllegalArgumentException - if either input is a non-empty GeometryCollection

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: 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.

equalsExact

public boolean equalsExact(Geometry other)
Returns true if the two Geometrys are exactly equal. Two Geometries are exactly equal iff: 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.

apply

public abstract void apply(CoordinateFilter filter)
Performs an operation with or on this Geometry's coordinates. If this method modifies any coordinate values, #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 Coordinates at all).

Parameters:
filter - the filter to apply to this Geometry's coordinates

apply

public abstract void apply(CoordinateSequenceFilter filter)
Performs an operation on the coordinates in this Geometry's CoordinateSequences. If this method modifies any coordinate values, #geometryChanged() must be called to update the geometry state.

Parameters:
filter - the filter to apply

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

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.

clone

public java.lang.Object clone()
Creates and returns a full copy of this Geometry object (including all coordinates contained by it). Subclasses are responsible for overriding this method and copying their internal data. Overrides should call this method first.

Returns:
a clone of this instance

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.


compareTo

public int compareTo(java.lang.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:

If the two Geometrys have the same class, their first elements are compared. If those are the same, the second elements are compared, etc.

Specified by:
compareTo in interface java.lang.Comparable
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(java.lang.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:

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

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.

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
Throws:
java.lang.IllegalArgumentException - if g is a GeometryCollection but not one of its subclasses

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

compareToSameClass

protected abstract int compareToSameClass(java.lang.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(java.lang.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

compare

protected int compare(java.util.Collection a,
                      java.util.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

equal

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