JTS Frequently Asked Questions

Last Update: September 18, 2008

A. General
1. What Java versions does JTS work with?

B. Design and Structure
1. How can I use JTS algorithms with a different geometry model?
2. Why does JTS allow geometries to be constructed with invalid topology?
3. What is the difference between a Point and a Coordinate?
4. Does JTS support 3D operations?

C. Geometry Predicates
1. How are spatial predicates computed?
2. Why does relate(POINT(20 20), POINT(20 30) ,"FF0FFF0F2") = true ?
3. Why is the result of a predicate different in JTS than in another software application/library ?

D. Robustness & Precision
1. Why is a TopologyException thrown?
2. What is a "robustness failure"?
3. What is a "topology collapse"?
4. What is the PrecisionModel for?
5. Why does JTS not enforce the PrecisionModel I specify?
6. Why do the overlay operations not obey the axioms of set theory?

E. Algorithms
1. Are there any references which describe the algorithms used in JTS?
2. Is there a skeletonization algorithm with works with JTS?


A. General


What Java versions does JTS work with?

JTS is developed using Java 1.4.2. It should work with all newer versions. With a small amount of work the library can be made to work with almost all previous Java versions as well.

B. Design and Structure


How can I use JTS algorithms with a different geometry model?

The solution to this is to use Facade objects which wrap the non-JTS geometry model classes. In order to avoid having to create and copy large numbers of Coordinate objects, JTS provides the CoordinateSequence interface. A CoordinateSequence-based adapter can be written for whatever structure the foreign model uses to represent sequences of points. JTS Geometry objects will still need to be created to represent the structure of the geometries containing the points, but these are relatively lightweight in comparison.


Why does JTS allow geometries to be constructed with invalid topology?

JTS intentionally allows topologically invalid geometries to be constructed for the following reasons:

  1. It allows a wider set of geometry to be read, stored and written from external data sources
  2. It allows geometries to be constructed and then validated
  3. It avoids the costly overhead of validating topology every time a geometry is constructed

What is the difference between a Point and a Coordinate?

A Coordinate is a relatively simple class which represents a location on the Cartesian plane (optionally with an associated height value). Coordinates are usually treated as mutable objects, in order to simplify certain algorithms.

A Point is a subclass of Geometry that also represents a location on the Cartesian plane. It is a "heavy-weight" object (which for instance may contain an envelope) which support all methods that apply to Geometrys.


Does JTS support 3D operations?

The short answer to this is no. JTS does allow Coordinates to carry an elevation or Z value. This does not provide true 3D support, but does allow "2.5D" uses which are required in some geospatial applications.

C. Geometry Predicates


C1. How are spatial predicates computed?

The two input geometries are decomposed into labelled topology graphs (GeometryGraphs). The labels are on the nodes and edges of the graphs. They contain full information about the topology of the node/edge in the points/lines/polygons of the original geometry. The labelled topology graphs are merged. This includes merging the labels wherever there is common nodes or edges. For each geometry at each node, the label information is propagated to all edges incident on that node. The resulting relationship (Intersection Matrix, or IM) is determined by the merged label information at the nodes of the merged graph. The labelling of each node and its incident edges is inspected, and the topological relationship information it contributes is added to the overall IM. At the end of this process the IM has been completely determined.


C2. Why does relate(POINT(20 20), POINT(20 30) ,"FF0FFF0F2") = true?

According to the SFS 1.1, section 2.1.3:

The boundary of a Point is the empty set
Since points do not have boundaries, all the intersection matrix entries relating to the geometry boundaries are "F".

In some situations it is desirable to use a different definition for determining whether geometry endpoints are on their boundary. To support this, JTS provides the ability to specify a custom BoundaryNodeRule to the RelateOp class.


C3. Why is the result of a predicate different in JTS than in another software application/library ?

This is usually due to the fact that JTS predicates are computed exactly, using the full precision of the double-precision coordinates. Other geometry engines sometimes compute in lower precision, or round input coordinates, or use a tolerance when determining whether two lines intersect or cross.

As a specific example, in the following case:

A: POLYGON ((1368.62186660165 17722.3281808793, -1653 9287.5, 4038.14058906538 8613.02390521266, 1368.62186660165 17722.3281808793))

B: POLYGON ((-5846 9287.5, 7453 8380, 9082 16600, -6326.5 18842, -5846 9287.5))
JTS reports A.overlaps(B) = true, whereas another application reports false. The Overlaps result is correct - the bottom right point in the triangle B lies outside the quadrilateral A. This is demonstrated by intersecting the bottom edge of A
LINESTRING (-5846 9287.5, 7453 8380)
with B. The value of the intersection is a line segment:
LINESTRING (4038.140589065375 8613.02390521266, 4038.14058906538 8613.02390521266)
which shows that B crosses the boundary of A, and thus overlaps A.

D. Robustness & Precision


Why is a TopologyException thrown?

TopologyExceptions are thrown when JTS encounters an inconsistency in the internal topology structures it creates to compute certain spatial operations (in particular, spatial predicates and overlay operations). These inconsistencies can happen for two reasons:

  1. Invalid input geometry
  2. Robustness failure due to floating-point roundoff errors causing incorrect results to be computed for internal operations (such as computing point-line orientation, computing the intersection of two line segments, or computing the noded arrangement of a set of line segments)
Unfortunately there is no guaranteed way of avoiding TopologyExceptions. Often they are caused by excessive precision in the input coordinates. Reducing the precision of the input coordinates (while still maintaining correct geometry topology) will often eliminate robustness issues.
Why do the overlay operations not obey the axioms of set theory?

This is sometimes presented as: "When I intersect two geometries why is the result not contained in either of the originals?" or: "When I union two geometries why does the result not contain either of the originals?"

The short answer to this is that it's for the same reason that floating-point computation does not fully obey the axioms of arithmetic. JTS uses double-precision floating point numbers to represent the coordinates of geometries. The finite representation of real numbers forces rounding to take place during arithmetic computation. This means that operations are not commutative or associative, which has the effect that arithmetic and geometric axioms are not maintained.

A major JTS design goal is that the output of geometric operations is "close" to the theoreticall correct result (using some small epsilon of tolerance and a suitable geometric distance metric.) This goal is generally met by the JTS algorithms.

In addition, JTS contains code which adjusts input geometries in small ways in order to try and prevent robustness errors from occuring. These changes also result in computed results which may not necessarily obey the set theory axiomns.

E. Algorithms


Are there any references which describe the algorithms used in JTS?

Many of the details of JTS algorithms (particularly in the areas of performance and robustness) are unique to JTS. However, the general design of the algorithms for computing spatial predicates and spatial overlay follow a generally accepted strategy for computing with 2-dimensional planar linear topological structures. Some papers which present similar approaches are:


Is there a skeletonization algorithm with works with JTS?

Yes. See the Refractions Research Skeletonizer