public class OverlayNG extends Object
Geometry
s,
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 bothThe 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
TopologyException
s 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: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:
INTERSECTION
and DIFFERENCE
operations.UNION
and SYMDIFFERENCE
operations
if the inputs have the same dimensionStrict mode has the following benefits:
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.
OverlayNGRobust
Modifier and Type | Field and Description |
---|---|
static int |
DIFFERENCE
The code for the Difference overlay operation.
|
static int |
INTERSECTION
The code for the Intersection overlay operation.
|
static int |
SYMDIFFERENCE
The code for the Symmetric Difference overlay operation.
|
static int |
UNION
The code for the Union overlay operation.
|
Constructor and Description |
---|
OverlayNG(Geometry geom0,
Geometry geom1,
int opCode)
Creates 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.
|
Modifier and Type | Method and Description |
---|---|
Geometry |
getResult()
Gets the result of the overlay operation.
|
static Geometry |
overlay(Geometry geom0,
Geometry geom1,
int opCode)
Computes an overlay operation on
the given geometry operands,
using the precision model of the geometry.
|
static Geometry |
overlay(Geometry geom0,
Geometry geom1,
int opCode,
Noder noder)
Computes an overlay operation on the given geometry operands,
using a supplied
Noder . |
static Geometry |
overlay(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 Geometry |
overlay(Geometry geom0,
Geometry geom1,
int opCode,
PrecisionModel pm,
Noder noder)
Computes an overlay operation on the given geometry operands,
using a supplied
Noder . |
void |
setOptimized(boolean isOptimized)
Sets whether overlay processing optimizations are enabled.
|
void |
setOutputEdges(boolean isOutputEdges) |
void |
setOutputNodedEdges(boolean isOutputNodedEdges) |
void |
setOutputResultEdges(boolean isOutputResultEdges) |
void |
setStrictMode(boolean isStrictMode)
Sets whether the overlay results are computed according to strict mode
semantics.
|
public static final int INTERSECTION
public static final int UNION
public static final int DIFFERENCE
public static final int SYMDIFFERENCE
public OverlayNG(Geometry geom0, Geometry geom1, PrecisionModel pm, int opCode)
geom0
- the A operand geometrygeom1
- the B operand geometry (may be null)pm
- the precision model to useopCode
- the overlay opcodepublic OverlayNG(Geometry geom0, Geometry geom1, int opCode)
The noder is chosen according to the precision model specified.
PrecisionModel.FIXED
a snap-rounding noder is used, and the computation is robust.
PrecisionModel.FLOATING
a non-snapping noder is used,
and this computation may not be robust.
If errors occur a TopologyException
is thrown.
geom0
- the A operand geometrygeom1
- the B operand geometry (may be null)opCode
- the overlay opcodepublic static Geometry overlay(Geometry geom0, Geometry geom1, int opCode, PrecisionModel pm)
geom0
- the first geometry argumentgeom1
- the second geometry argumentopCode
- the code for the desired overlay operationpm
- the precision model to usepublic static Geometry overlay(Geometry geom0, Geometry geom1, int opCode, PrecisionModel pm, Noder noder)
Noder
.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 usepublic static Geometry overlay(Geometry geom0, Geometry geom1, int opCode, Noder noder)
Noder
.geom0
- the first geometry argumentgeom1
- the second geometry argumentopCode
- the code for the desired overlay operationnoder
- the noder to usepublic static Geometry overlay(Geometry geom0, Geometry geom1, int opCode)
The noder is chosen according to the precision model specified.
PrecisionModel.FIXED
a snap-rounding noder is used, and the computation is robust.
PrecisionModel.FLOATING
a non-snapping noder is used,
and this computation may not be robust.
If errors occur a TopologyException
is thrown.
geom0
- the first argument geometrygeom1
- the second argument geometryopCode
- the code for the desired overlay operationpublic void setStrictMode(boolean isStrictMode)
INTERSECTION
and DIFFERENCE
operations.
UNION
and SYMDIFFERENCE
operations
if the inputs have the same dimension
isStrictMode
- true if strict mode is to be usedpublic void setOptimized(boolean isOptimized)
isOptimized
- whether to optimize processingpublic void setOutputEdges(boolean isOutputEdges)
isOutputEdges
- public void setOutputNodedEdges(boolean isOutputNodedEdges)
public void setOutputResultEdges(boolean isOutputResultEdges)
public Geometry getResult()
IllegalArgumentException
- if the input is not supported (e.g. a mixed-dimension geometry)TopologyException
- if a robustness error occursCopyright © 2022. All rights reserved.