Class OverlayNG
Geometrys,
using an explicit precision model to allow robust computation.
The overlay can be used to determine any of the following set-theoretic operations (boolean combinations) of the geometries:
INTERSECTION- all points which lie in both geometriesUNION- all points which lie in at least one geometryDIFFERENCE- all points which lie in the first geometry but not the secondSYMDIFFERENCE- all points which lie in one geometry but not both
invalid reference
GeometryCollection
The precision model used for the computation can be supplied independent of the precision model of the input geometry. The main use for this is to allow using a fixed precision for geometry with a floating precision model. This does two things: ensures robust computation; and forces the output to be validly rounded to the precision model.
For fixed precision models noding is performed using a SnapRoundingNoder.
This provides robust computation (as long as precision is limited to
around 13 decimal digits).
For floating precision an MCIndexNoder is used.
This is not fully robust, so can sometimes result in
TopologyExceptions being thrown.
For robust full-precision overlay see OverlayNGRobust.
A custom Noder can be supplied.
This allows using a more performant noding strategy in specific cases,
for instance in CoverageUnion.
Note:invalid input: '<'/b If a SnappingNoder is used
it is best to specify a fairly small snap tolerance,
since the intersection clipping optimization can
interact with the snapping to alter the result.
Optionally the overlay computation can process using strict mode
(via setStrictMode(boolean).
In strict mode result semantics are:
- Lines and Points resulting from topology collapses are not included in the result
- Result geometry is homogeneous
for the
INTERSECTIONandDIFFERENCEoperations. - Result geometry is homogeneous
for the
UNIONandSYMDIFFERENCEoperations if the inputs have the same dimension
Strict mode has the following benefits:
- Results are simpler
- Overlay operations are chainable without needing to remove lower-dimension elements
The original JTS overlay semantics corresponds to non-strict mode.
If a robustness error occurs, a TopologyException is thrown.
These are usually caused by numerical rounding causing the noding output
to not be fully noded.
For robust computation with full-precision OverlayNGRobust can be used.
- Author:
- mdavis
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe code for the Difference overlay operation.static final intThe code for the Intersection overlay operation.static final intThe code for the Symmetric Difference overlay operation.static final intThe code for the Union overlay operation. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an overlay operation on the given geometries using the precision model of the geometries.OverlayNG(Geometry geom0, Geometry geom1, PrecisionModel pm, int opCode) Creates an overlay operation on the given geometries, with a defined precision model. -
Method Summary
Modifier and TypeMethodDescriptionGets the result of the overlay operation.static GeometryComputes an overlay operation on the given geometry operands, using the precision model of the geometry. and an appropriate noder.static Geometryoverlay(Geometry geom0, Geometry geom1, int opCode, PrecisionModel pm) Computes an overlay operation for the given geometry operands, with the noding strategy determined by the precision model.static Geometryoverlay(Geometry geom0, Geometry geom1, int opCode, PrecisionModel pm, Noder noder) Computes an overlay operation on the given geometry operands, using a suppliedNoder.static GeometryComputes an overlay operation on the given geometry operands, using a suppliedNoder.voidsetOptimized(boolean isOptimized) Sets whether overlay processing optimizations are enabled.voidsetOutputEdges(boolean isOutputEdges) voidsetOutputNodedEdges(boolean isOutputNodedEdges) voidsetOutputResultEdges(boolean isOutputResultEdges) voidsetStrictMode(boolean isStrictMode) Sets whether the overlay results are computed according to strict mode semantics.
-
Field Details
-
INTERSECTION
public static final int INTERSECTIONThe code for the Intersection overlay operation.- See Also:
-
UNION
public static final int UNIONThe code for the Union overlay operation.- See Also:
-
DIFFERENCE
public static final int DIFFERENCEThe code for the Difference overlay operation.- See Also:
-
SYMDIFFERENCE
public static final int SYMDIFFERENCEThe code for the Symmetric Difference overlay operation.- See Also:
-
-
Constructor Details
-
OverlayNG
Creates an overlay operation on the given geometries, with a defined precision model. The noding strategy is determined by the precision model.- Parameters:
geom0- the A operand geometrygeom1- the B operand geometry (may be null)pm- the precision model to useopCode- the overlay opcode
-
OverlayNG
Creates an overlay operation on the given geometries using the precision model of the geometries.The noder is chosen according to the precision model specified.
- For
PrecisionModel.FIXEDa snap-rounding noder is used, and the computation is robust. - For
PrecisionModel.FLOATINGa non-snapping noder is used, and this computation may not be robust. If errors occur aTopologyExceptionis thrown.
- Parameters:
geom0- the A operand geometrygeom1- the B operand geometry (may be null)opCode- the overlay opcode
- For
-
-
Method Details
-
overlay
Computes an overlay operation for the given geometry operands, with the noding strategy determined by the precision model.- Parameters:
geom0- the first geometry argumentgeom1- the second geometry argumentopCode- the code for the desired overlay operationpm- the precision model to use- Returns:
- the result of the overlay operation
-
overlay
public static Geometry overlay(Geometry geom0, Geometry geom1, int opCode, PrecisionModel pm, Noder noder) Computes an overlay operation on the given geometry operands, using a suppliedNoder.- Parameters:
geom0- the first geometry argumentgeom1- the second geometry argumentopCode- the code for the desired overlay operationpm- the precision model to use (which may be null if the noder does not use one)noder- the noder to use- Returns:
- the result of the overlay operation
-
overlay
Computes an overlay operation on the given geometry operands, using a suppliedNoder.- Parameters:
geom0- the first geometry argumentgeom1- the second geometry argumentopCode- the code for the desired overlay operationnoder- the noder to use- Returns:
- the result of the overlay operation
-
overlay
Computes an overlay operation on the given geometry operands, using the precision model of the geometry. and an appropriate noder.The noder is chosen according to the precision model specified.
- For
PrecisionModel.FIXEDa snap-rounding noder is used, and the computation is robust. - For
PrecisionModel.FLOATINGa non-snapping noder is used, and this computation may not be robust. If errors occur aTopologyExceptionis thrown.
- Parameters:
geom0- the first argument geometrygeom1- the second argument geometryopCode- the code for the desired overlay operation- Returns:
- the result of the overlay operation
- For
-
setStrictMode
public void setStrictMode(boolean isStrictMode) Sets whether the overlay results are computed according to strict mode semantics.- Lines resulting from topology collapse are not included
- Result geometry is homogeneous
for the
INTERSECTIONandDIFFERENCEoperations. - Result geometry is homogeneous
for the
UNIONandSYMDIFFERENCEoperations if the inputs have the same dimension
- Parameters:
isStrictMode- true if strict mode is to be used
-
setOptimized
public void setOptimized(boolean isOptimized) Sets whether overlay processing optimizations are enabled. It may be useful to disable optimizations for testing purposes. Default is TRUE (optimization enabled).- Parameters:
isOptimized- whether to optimize processing
-
setOutputEdges
public void setOutputEdges(boolean isOutputEdges) - Parameters:
isOutputEdges-
-
setOutputNodedEdges
public void setOutputNodedEdges(boolean isOutputNodedEdges) -
setOutputResultEdges
public void setOutputResultEdges(boolean isOutputResultEdges) -
getResult
Gets the result of the overlay operation.- Returns:
- the result of the overlay operation.
- Throws:
IllegalArgumentException- if the input is not supported (e.g. a mixed-dimension geometry)TopologyException- if a robustness error occurs
-