Class OverlayOp
java.lang.Object
org.locationtech.jts.operation.GeometryGraphOperation
org.locationtech.jts.operation.overlay.OverlayOp
Computes the geometric overlay of two
Geometry
s. The overlay
can be used to determine any boolean combination of the geometries.- Version:
- 1.7
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The code for the Difference overlay operation.private EdgeList
private GeometryFactory
private PlanarGraph
static final int
The code for the Intersection overlay operation.private final PointLocator
private Geometry
private List
private List
private List
static final int
The code for the Symmetric Difference overlay operation.static final int
The code for the Union overlay operation.Fields inherited from class org.locationtech.jts.operation.GeometryGraphOperation
arg, li, resultPrecisionModel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
If both a dirEdge and its sym are marked as being in the result, cancel them out.private Geometry
computeGeometry
(List resultPointList, List resultLineList, List resultPolyList, int opcode) private void
Compute initial labelling for all DirectedEdges at each node.private void
Update the labels for edges according to their depths.private void
computeOverlay
(int opCode) private void
copyPoints
(int argIndex) Copy all nodes from an arg geometry into this graph.static Geometry
createEmptyResult
(int overlayOpCode, Geometry a, Geometry b, GeometryFactory geomFact) Creates an empty result geometry of the appropriate dimension, based on the given overlay operation and the dimensions of the inputs.private void
findResultAreaEdges
(int opCode) Find all edges whose label indicates that they are in the result area(s), according to the operation being performed.getGraph()
Gets the graph constructed to compute the overlay.getResultGeometry
(int overlayOpCode) Gets the result of the overlay for a given overlay operation.protected void
Insert an edge from one of the noded input graphs.private void
insertUniqueEdges
(List edges) private boolean
isCovered
(Coordinate coord, List geomList) boolean
isCoveredByA
(Coordinate coord) Tests if an L edge should be included in the result or not.boolean
isCoveredByLA
(Coordinate coord) Tests if a point node should be included in the result or not.static boolean
isResultOfOp
(int loc0, int loc1, int overlayOpCode) Tests whether a point with givenLocation
s relative to two geometries is contained in the result of overlaying the geometries using a given overlay operation.static boolean
isResultOfOp
(Label label, int opCode) Tests whether a point with a given topologicalLabel
relative to two geometries is contained in the result of overlaying the geometries using a given overlay operation.private void
labelIncompleteNode
(Node n, int targetIndex) Label an isolated node with its relationship to the target geometry.private void
Incomplete nodes are nodes whose labels are incomplete.private void
For nodes which have edges from only one Geometry incident on them, the previous step will have left their dirEdges with no labelling for the other Geometry.static Geometry
Computes an overlay operation for the given geometry arguments.private void
If edges which have undergone dimensional collapse are found, replace them with a new edge which is a L edgeprivate static int
resultDimension
(int opCode, Geometry g0, Geometry g1) private void
Methods inherited from class org.locationtech.jts.operation.GeometryGraphOperation
getArgGeometry, setComputationPrecision
-
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:
-
ptLocator
-
geomFact
-
resultGeom
-
graph
-
edgeList
-
resultPolyList
-
resultLineList
-
resultPointList
-
-
Constructor Details
-
OverlayOp
Constructs an instance to compute a single overlay operation for the given geometries.- Parameters:
g0
- the first geometry argumentg1
- the second geometry argument
-
-
Method Details
-
overlayOp
Computes an overlay operation for the given geometry arguments.- Parameters:
geom0
- the first geometry argumentgeom1
- the second geometry argumentopCode
- the code for the desired overlay operation- Returns:
- the result of the overlay operation
- Throws:
TopologyException
- if a robustness problem is encountered
-
isResultOfOp
Tests whether a point with a given topologicalLabel
relative to two geometries is contained in the result of overlaying the geometries using a given overlay operation.The method handles arguments of
Location.NONE
correctly- Parameters:
label
- the topological label of the pointopCode
- the code for the overlay operation to test- Returns:
- true if the label locations correspond to the overlayOpCode
-
isResultOfOp
public static boolean isResultOfOp(int loc0, int loc1, int overlayOpCode) Tests whether a point with givenLocation
s relative to two geometries is contained in the result of overlaying the geometries using a given overlay operation.The method handles arguments of
Location.NONE
correctly- Parameters:
loc0
- the code for the location in the first geometryloc1
- the code for the location in the second geometryoverlayOpCode
- the code for the overlay operation to test- Returns:
- true if the locations correspond to the overlayOpCode
-
getResultGeometry
Gets the result of the overlay for a given overlay operation.Note: this method can be called once only.
- Parameters:
overlayOpCode
- the overlay operation to perform- Returns:
- the compute result geometry
- Throws:
TopologyException
- if a robustness problem is encountered
-
getGraph
Gets the graph constructed to compute the overlay.- Returns:
- the overlay graph
-
computeOverlay
private void computeOverlay(int opCode) -
insertUniqueEdges
-
insertUniqueEdge
Insert an edge from one of the noded input graphs. Checks edges that are inserted to see if an identical edge already exists. If so, the edge is not inserted, but its label is merged with the existing edge. -
computeLabelsFromDepths
private void computeLabelsFromDepths()Update the labels for edges according to their depths. For each edge, the depths are first normalized. Then, if the depths for the edge are equal, this edge must have collapsed into a line edge. If the depths are not equal, update the label with the locations corresponding to the depths (i.e. a depth of 0 corresponds to a Location of EXTERIOR, a depth of 1 corresponds to INTERIOR) -
replaceCollapsedEdges
private void replaceCollapsedEdges()If edges which have undergone dimensional collapse are found, replace them with a new edge which is a L edge -
copyPoints
private void copyPoints(int argIndex) Copy all nodes from an arg geometry into this graph. The node label in the arg geometry overrides any previously computed label for that argIndex. (E.g. a node may be an intersection node with a previously computed label of BOUNDARY, but in the original arg Geometry it is actually in the interior due to the Boundary Determination Rule) -
computeLabelling
private void computeLabelling()Compute initial labelling for all DirectedEdges at each node. In this step, DirectedEdges will acquire a complete labelling (i.e. one with labels for both Geometries) only if they are incident on a node which has edges for both Geometries -
mergeSymLabels
private void mergeSymLabels()For nodes which have edges from only one Geometry incident on them, the previous step will have left their dirEdges with no labelling for the other Geometry. However, the sym dirEdge may have a labelling for the other Geometry, so merge the two labels. -
updateNodeLabelling
private void updateNodeLabelling() -
labelIncompleteNodes
private void labelIncompleteNodes()Incomplete nodes are nodes whose labels are incomplete. (e.g. the location for one Geometry is null). These are either isolated nodes, or nodes which have edges from only a single Geometry incident on them. Isolated nodes are found because nodes in one graph which don't intersect nodes in the other are not completely labelled by the initial process of adding nodes to the nodeList. To complete the labelling we need to check for nodes that lie in the interior of edges, and in the interior of areas.When each node labelling is completed, the labelling of the incident edges is updated, to complete their labelling as well.
-
labelIncompleteNode
Label an isolated node with its relationship to the target geometry. -
findResultAreaEdges
private void findResultAreaEdges(int opCode) Find all edges whose label indicates that they are in the result area(s), according to the operation being performed. Since we want polygon shells to be oriented CW, choose dirEdges with the interior of the result on the RHS. Mark them as being in the result. Interior Area edges are the result of dimensional collapses. They do not form part of the result area boundary. -
cancelDuplicateResultEdges
private void cancelDuplicateResultEdges()If both a dirEdge and its sym are marked as being in the result, cancel them out. -
isCoveredByLA
Tests if a point node should be included in the result or not.- Parameters:
coord
- the point coordinate- Returns:
- true if the coordinate point is covered by a result Line or Area geometry
-
isCoveredByA
Tests if an L edge should be included in the result or not.- Parameters:
coord
- the point coordinate- Returns:
- true if the coordinate point is covered by a result Area geometry
-
isCovered
- Returns:
- true if the coord is located in the interior or boundary of a geometry in the list.
-
computeGeometry
-
createEmptyResult
public static Geometry createEmptyResult(int overlayOpCode, Geometry a, Geometry b, GeometryFactory geomFact) Creates an empty result geometry of the appropriate dimension, based on the given overlay operation and the dimensions of the inputs. The created geometry is always an atomic geometry, not a collection.The empty result is constructed using the following rules:
INTERSECTION
- result has the dimension of the lowest input dimensionUNION
- result has the dimension of the highest input dimensionDIFFERENCE
- result has the dimension of the left-hand inputSYMDIFFERENCE
- result has the dimension of the highest input dimension (since the symmetric Difference is the union of the differences).
- Parameters:
overlayOpCode
- the code for the overlay operation being performeda
- an input geometryb
- an input geometrygeomFact
- the geometry factory being used for the operation- Returns:
- an empty atomic geometry of the appropriate dimension
-
resultDimension
-