Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
com.vividsolutions.jts.geom.Geometry
public abstract class Geometry
extends java.lang.Object
implements Cloneable, Comparable, Serializable
Geometry
.
clone
returns a deep copy of the object.
GeometryCollection
s would be useful,
GeometryCollection
s are not supported as arguments to binary
predicates (other than convexHull
) or the relate
method.
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 GeometryCollection
s would be useful,
GeometryCollections
are not supported as arguments to the set-theoretic methods.
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
Geometry
s returned from spatial analysis methods. The canonical
form is a Geometry
which is simple and noded:
isSimple
.
LineString
s. It
means that all intersection points on LineString
s will be
present as endpoints of LineString
s in the result.
Geometry
s. These new points arise from intersections between line segments in the
edges of the input Geometry
s. 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.
Field Summary | |
protected int |
|
protected Envelope |
|
Constructor Summary | |
|
Method Summary | |
abstract void |
|
abstract void |
|
abstract void |
|
Geometry |
|
Geometry | |
protected void |
|
Object |
|
protected int |
|
int |
|
protected abstract int |
|
protected abstract Envelope |
|
boolean | |
Geometry |
|
boolean | |
Geometry |
|
boolean | |
double | |
protected boolean |
|
boolean | |
boolean |
|
abstract boolean |
|
void |
|
protected void |
|
double |
|
abstract Geometry |
|
abstract int |
|
Point |
|
abstract Coordinate |
|
abstract Coordinate[] |
|
abstract int |
|
Geometry |
|
Envelope |
|
GeometryFactory |
|
Geometry |
|
abstract String |
|
Point |
|
double |
|
int |
|
abstract int |
|
PrecisionModel |
|
int |
|
Object |
|
protected static boolean |
|
protected static boolean |
|
Geometry |
|
boolean |
|
abstract boolean |
|
protected boolean |
|
boolean | |
abstract boolean |
|
boolean |
|
boolean |
|
abstract void |
|
boolean | |
IntersectionMatrix | |
boolean |
|
void |
|
void |
|
Geometry |
|
String |
|
String |
|
boolean | |
Geometry | |
boolean |
public abstract void apply(CoordinateFilter filter)
Performs an operation with or on thisGeometry
'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 thisGeometry
's coordinates
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 thisGeometry
.
public abstract void apply(GeometryFilter filter)
Performs an operation with or on thisGeometry
and its subelementGeometry
s (if any). Only GeometryCollections and subclasses have subelement Geometry's.
- Parameters:
filter
- the filter to apply to thisGeometry
(and its children, if it is aGeometryCollection
).
public Geometry buffer(double distance)
Returns a buffer region around thisGeometry
having the given width. The buffer of a Geometry is the Minkowski sum or difference of the Geometry with a disc of radiusdistance
.
- Parameters:
distance
- the width of the buffer, interpreted according to thePrecisionModel
of theGeometry
- Returns:
- all points whose distance from this
Geometry
are less than or equal todistance
public Geometry buffer(double distance, int quadrantSegments)
Returns a buffer region around thisGeometry
having the given width and with a specified number of segments used to approximate curves. The buffer of a Geometry is the Minkowski sum of the Geometry with a disc of radiusdistance
. Curves in the buffer polygon are approximated with line segments. This method allows specifying the accuracy of that approximation.
- Parameters:
distance
- the width of the buffer, interpreted according to thePrecisionModel
of theGeometry
quadrantSegments
- the number of segments to use to approximate a quadrant of a circle
- Returns:
- all points whose distance from this
Geometry
are less than or equal todistance
protected void checkNotGeometryCollection(Geometry g)
Throws an exception ifg
's class isGeometryCollection
. (Its subclasses do not trigger an exception).
- Parameters:
g
- theGeometry
to check
public Object clone()
protected int compare(Collection a, Collection b)
Returns the first non-zero result ofcompareTo
encountered as the twoCollection
s 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. Ifb
completes beforea
, a positive number is returned; if a before b, a negative number.
- Parameters:
a
- aCollection
ofComparable
sb
- aCollection
ofComparable
s
- Returns:
- the first non-zero
compareTo
result, if any; otherwise, zero
public int compareTo(Object o)
Returns whether thisGeometry
is greater than, equal to, or less than anotherGeometry
. If their classes are different, they are compared using the following ordering:If the two
- Point (lowest)
- MultiPoint
- LineString
- LinearRing
- MultiLineString
- Polygon
- MultiPolygon
- GeometryCollection (highest)
Geometry
s have the same class, their first elements are compared. If those are the same, the second elements are compared, etc.
- Parameters:
o
- aGeometry
with which to compare thisGeometry
- Returns:
- a positive number, 0, or a negative number, depending on whether this object is greater than, equal to, or less than
o
, as defined in "Normal Form For Geometry" in the JTS Technical Specifications
protected abstract int compareToSameClass(Object o)
Returns whether thisGeometry
is greater than, equal to, or less than anotherGeometry
having the same class.
- Parameters:
o
- aGeometry
having the same class as thisGeometry
- Returns:
- a positive number, 0, or a negative number, depending on whether this object is greater than, equal to, or less than
o
, as defined in "Normal Form For Geometry" in the JTS Technical Specifications
protected abstract Envelope computeEnvelopeInternal()
Returns the minimum and maximum x and y values in thisGeometry
, or a nullEnvelope
if thisGeometry
is empty. UnlikegetEnvelopeInternal
, this method calculates theEnvelope
each time it is called;getEnvelopeInternal
caches the result of this method.
- Returns:
- this
Geometry
s bounding box; if theGeometry
is empty,Envelope#isNull
will returntrue
public boolean contains(Geometry g)
Returnstrue
ifother.within(this)
returnstrue
.
- Parameters:
- Returns:
true
if thisGeometry
containsother
public Geometry convexHull()
Returns the smallest convexPolygon
that contains all the points in theGeometry
. This obviously applies only toGeometry
s which contain 3 or more points; the results for degenerate cases are specified as follows:
Number of Point
s in argumentGeometry
Geometry
class of result0 empty GeometryCollection
1 Point
2 LineString
3 or more Polygon
- Returns:
- the minimum-area convex polygon containing this
Geometry
' s points
public boolean crosses(Geometry g)
Returnstrue
if the DE-9IM intersection matrix for the twoGeometry
s is.
- T*T****** (for a point and a curve, a point and an area or a line and an area)
- 0******** (for two curves)
- Parameters:
- Returns:
true
if the twoGeometry
s cross. For this function to returntrue
, theGeometry
s must be a point and a curve; a point and a surface; two curves; or a curve and a surface.
public Geometry difference(Geometry other)
Returns aGeometry
representing the points making up thisGeometry
that do not make upother
. This method returns the closure of the resultantGeometry
.
- Parameters:
other
- theGeometry
with which to compute the difference
- Returns:
- the point set difference of this
Geometry
withother
public boolean disjoint(Geometry g)
Returnstrue
if the DE-9IM intersection matrix for the twoGeometry
s is FF*FF****.
- Parameters:
- Returns:
true
if the twoGeometry
s are disjoint
public double distance(Geometry g)
Returns the minimum distance between thisGeometry
and theGeometry
g
- Parameters:
g
- theGeometry
from which to compute the distance
public boolean equals(Geometry g)
Returnstrue
if the DE-9IM intersection matrix for the twoGeometry
s is T*F**FFF*.
- Parameters:
- Returns:
true
if the twoGeometry
s are equal
public boolean equalsExact(Geometry other)
Returns true if the twoGeometry
s are exactly equal. Two Geometries are exactly equal iff:If this and the other
- they have the same class
- they have the same values of Coordinates in their internal Coordinate lists, in exactly the same order.
Geometry
s are composites and any children are notGeometry
s, returns false. This provides a stricter test of equality thanequals
.
- Parameters:
other
- theGeometry
with which to compare thisGeometry
- Returns:
true
if this and the otherGeometry
are of the same class and have equal internal data.
public abstract boolean equalsExact(Geometry other, double tolerance)
Returns true if the twoGeometry
s are exactly equal, up to a specified tolerance. Two Geometries are exactly within a tolerance equal iff:If this and the other
- they have the same class
- they have the same values of Coordinates, within the given tolerance distance, in their internal Coordinate lists, in exactly the same order.
Geometry
s are composites and any children are notGeometry
s, returns false.
- Parameters:
other
- theGeometry
with which to compare thisGeometry
- Returns:
true
if this and the otherGeometry
are of the same class and have equal internal data.
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 itsEnvelope
).
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)
public double getArea()
Returns the area of thisGeometry
. 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
public abstract Geometry getBoundary()
Returns the boundary, or the empty geometry if thisGeometry
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
public abstract int getBoundaryDimension()
Returns the dimension of thisGeometry
s 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.
public Point getCentroid()
Computes the centroid of thisGeometry
. 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
public abstract Coordinate getCoordinate()
Returns a vertex of thisGeometry
.
- Returns:
- a
Coordinate
which is a vertex of thisGeometry
. Returnsnull
if this Geometry is empty
public abstract Coordinate[] getCoordinates()
Returns thisGeometry
s vertices. If you modify the coordinates in this array, be sure to call #geometryChanged afterwards. TheGeometry
s contained by compositeGeometry
s must be Geometry's; that is, they must implementgetCoordinates
.
- Returns:
- the vertices of this
Geometry
public abstract int getDimension()
Returns the dimension of thisGeometry
.
- Returns:
- the dimension of the class implementing this interface, whether or not this object is the empty geometry
public Geometry getEnvelope()
Returns thisGeometry
s bounding box. If thisGeometry
is the empty geometry, returns an emptyPoint
. If theGeometry
is a point, returns a non-emptyPoint
. Otherwise, returns aPolygon
whose points are (minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy), (minx, miny).
- Returns:
- an empty
Point
(for emptyGeometry
s), aPoint
(forPoint
s) or aPolygon
(in all other cases)
public Envelope getEnvelopeInternal()
Returns the minimum and maximum x and y values in thisGeometry
, or a nullEnvelope
if thisGeometry
is empty.
- Returns:
- this
Geometry
s bounding box; if theGeometry
is empty,Envelope#isNull
will returntrue
public GeometryFactory getFactory()
Gets the factory which contains the context in which this geometry was created.
- Returns:
- the factory for this geometry
public Geometry getGeometryN(int n)
Returns an elementGeometry
from aGeometryCollection
(orthis
, if the geometry is not a collection).
- Parameters:
n
- the index of the geometry element
- Returns:
- the n'th geometry contained in this geometry
public abstract String getGeometryType()
Returns the name of this object'scom.vivid.jts.geom
interface.
- Returns:
- the name of this
Geometry
s most specificcom.vividsolutions.jts.geom
interface
public Point getInteriorPoint()
Computes an interior point of thisGeometry
. 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
public double getLength()
Returns the length of thisGeometry
. 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
public int getNumGeometries()
Returns the number ofGeometry
s in aGeometryCollection
(or 1, if the geometry is not a collection).
- Returns:
- the number of geometries contained in this geometry
public abstract int getNumPoints()
Returns the count of thisGeometry
s vertices. TheGeometry
s contained by compositeGeometry
s must be Geometry's; that is, they must implementgetNumPoints
- Returns:
- the number of vertices in this
Geometry
public PrecisionModel getPrecisionModel()
Returns thePrecisionModel
used by theGeometry
.
- Returns:
- the specification of the grid of allowable points, for this
Geometry
and all otherGeometry
s
public int getSRID()
Deprecated. use
getUserData
insteadReturns the ID of the Spatial Reference System used by theGeometry
. JTS supports Spatial Reference System information in the simple way defined in the SFS. A Spatial Reference System ID (SRID) is present in eachGeometry
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.
public Object getUserData()
Gets the user data object for this geometry, if any.
- Returns:
- the user data object, or
null
if none set
protected static boolean hasNonEmptyElements(Geometry[] geometries)
Returns true if the array contains any non-emptyGeometry
s.
- Parameters:
geometries
- an array ofGeometry
s; no elements may benull
- Returns:
true
if any of theGeometry
sisEmpty
methods returnfalse
protected static boolean hasNullElements(Object[] array)
Returns true if the array contains anynull
elements.
- Parameters:
array
- an array to validate
- Returns:
true
if any ofarray
s elements arenull
public Geometry intersection(Geometry other)
Returns aGeometry
representing the points shared by thisGeometry
andother
.
- Parameters:
other
- theGeometry
with which to compute the intersection
- Returns:
- the points common to the two
Geometry
s
public boolean intersects(Geometry g)
Returnstrue
ifdisjoint
returns false.
- Parameters:
- Returns:
true
if the twoGeometry
s intersect
public abstract boolean isEmpty()
Returns whether or not the set of points in thisGeometry
is empty.
- Returns:
true
if thisGeometry
equals the empty geometry
protected boolean isEquivalentClass(Geometry other)
Returns whether the twoGeometry
s are equal, from the point of view of theequalsExact
method. Called byequalsExact
. In general, twoGeometry
classes are considered to be "equivalent" only if they are the same class. An exception isLineString
, which is considered to be equivalent to its subclasses.
- Parameters:
other
- theGeometry
with which to compare thisGeometry
for equality
- Returns:
true
if the classes of the twoGeometry
s are considered to be equal by theequalsExact
method.
public boolean isRectangle()
public abstract boolean isSimple()
Returns false if theGeometry
not simple. Subclasses provide their own definition of "simple". If thisGeometry
is empty, returnstrue
. In general, the SFS specifications of simplicity seem to follow the following rule:For all empty
- A Geometry is simple iff the only self-intersections are at boundary points.
Geometry
s,isSimple
=true
.
- Returns:
true
if thisGeometry
has any points of self-tangency, self-intersection or other anomalous points
public boolean isValid()
Tests the validity of thisGeometry
. Subclasses provide their own definition of "valid".
- Returns:
true
if thisGeometry
is valid
- See Also:
IsValidOp
public boolean isWithinDistance(Geometry geom, double distance)
Tests whether the distance from thisGeometry
to another is less than or equal to a specified value.
- Parameters:
geom
- the Geometry to check the distance todistance
- the distance value to compare
- Returns:
true
if the geometries are less thandistance
apart.
public abstract void normalize()
Converts thisGeometry
to normal form (or canonical form ). Normal form is a unique representation forGeometry
s. It can be used to test whether twoGeometry
s 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.
public boolean overlaps(Geometry g)
Returnstrue
if the DE-9IM intersection matrix for the twoGeometry
s is.
- T*T***T** (for two points or two surfaces)
- 1*T***T** (for two curves)
- Parameters:
- Returns:
true
if the twoGeometry
s overlap. For this function to returntrue
, theGeometry
s must be two points, two curves or two surfaces.
public IntersectionMatrix relate(Geometry g)
Returns the DE-9IM intersection matrix for the twoGeometry
s.
- Parameters:
- Returns:
- a matrix describing the intersections of the interiors, boundaries and exteriors of the two
Geometry
s
public boolean relate(Geometry g, String intersectionPattern)
Returnstrue
if the elements in the DE-9IM intersection matrix for the twoGeometry
s match the elements inintersectionPattern
, which may be:For more information on the DE-9IM, see the OpenGIS Simple Features Specification.
- 0
- 1
- 2
- T ( = 0, 1 or 2)
- F ( = -1)
- * ( = -1, 0, 1 or 2)
- Parameters:
intersectionPattern
- the pattern against which to check the intersection matrix for the twoGeometry
s
- Returns:
true
if the DE-9IM intersection matrix for the twoGeometry
s matchintersectionPattern
public void setSRID(int SRID)
Deprecated. use
setUserData
insteadSets the ID of the Spatial Reference System used by theGeometry
.
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
public Geometry symDifference(Geometry other)
Returns a set combining the points in thisGeometry
not inother
, and the points inother
not in thisGeometry
. This method returns the closure of the resultantGeometry
.
- Parameters:
other
- theGeometry
with which to compute the symmetric difference
- Returns:
- the point set symmetric difference of this
Geometry
withother
public String toString()
public String toText()
Returns the Well-known Text representation of thisGeometry
. For a definition of the Well-known Text format, see the OpenGIS Simple Features Specification.
- Returns:
- the Well-known Text representation of this
Geometry
public boolean touches(Geometry g)
Returnstrue
if the DE-9IM intersection matrix for the twoGeometry
s is FT*******, F**T***** or F***T****.
- Parameters:
- Returns:
true
if the twoGeometry
s touch; Returns false if bothGeometry
s are points
public Geometry union(Geometry other)
Returns aGeometry
representing all the points in thisGeometry
andother
.
- Parameters:
other
- theGeometry
with which to compute the union
- Returns:
- a set combining the points of this
Geometry
and the points ofother
public boolean within(Geometry g)
Returnstrue
if the DE-9IM intersection matrix for the twoGeometry
s is T*F**F***.
- Parameters:
- Returns:
true
if thisGeometry
is withinother