Class OverlayOp

java.lang.Object
org.locationtech.jts.operation.GeometryGraphOperation
org.locationtech.jts.operation.overlay.OverlayOp

public class OverlayOp extends GeometryGraphOperation
Computes the geometric overlay of two Geometrys. The overlay can be used to determine any boolean combination of the geometries.
Version:
1.7
  • Field Details

    • INTERSECTION

      public static final int INTERSECTION
      The code for the Intersection overlay operation.
      See Also:
    • UNION

      public static final int UNION
      The code for the Union overlay operation.
      See Also:
    • DIFFERENCE

      public static final int DIFFERENCE
      The code for the Difference overlay operation.
      See Also:
    • SYMDIFFERENCE

      public static final int SYMDIFFERENCE
      The code for the Symmetric Difference overlay operation.
      See Also:
    • ptLocator

      private final PointLocator ptLocator
    • geomFact

      private GeometryFactory geomFact
    • resultGeom

      private Geometry resultGeom
    • graph

      private PlanarGraph graph
    • edgeList

      private EdgeList edgeList
    • resultPolyList

      private List resultPolyList
    • resultLineList

      private List resultLineList
    • resultPointList

      private List resultPointList
  • Constructor Details

    • OverlayOp

      public OverlayOp(Geometry g0, Geometry g1)
      Constructs an instance to compute a single overlay operation for the given geometries.
      Parameters:
      g0 - the first geometry argument
      g1 - the second geometry argument
  • Method Details

    • overlayOp

      public static Geometry overlayOp(Geometry geom0, Geometry geom1, int opCode)
      Computes an overlay operation for the given geometry arguments.
      Parameters:
      geom0 - the first geometry argument
      geom1 - the second geometry argument
      opCode - the code for the desired overlay operation
      Returns:
      the result of the overlay operation
      Throws:
      TopologyException - if a robustness problem is encountered
    • isResultOfOp

      public static boolean isResultOfOp(Label label, int opCode)
      Tests whether a point with a given topological Label 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 point
      opCode - 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 given Locations 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 geometry
      loc1 - the code for the location in the second geometry
      overlayOpCode - the code for the overlay operation to test
      Returns:
      true if the locations correspond to the overlayOpCode
    • getResultGeometry

      public Geometry getResultGeometry(int overlayOpCode)
      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

      public PlanarGraph getGraph()
      Gets the graph constructed to compute the overlay.
      Returns:
      the overlay graph
    • computeOverlay

      private void computeOverlay(int opCode)
    • insertUniqueEdges

      private void insertUniqueEdges(List edges)
    • insertUniqueEdge

      protected void insertUniqueEdge(Edge e)
      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

      private void labelIncompleteNode(Node n, int targetIndex)
      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

      public boolean isCoveredByLA(Coordinate coord)
      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

      public boolean isCoveredByA(Coordinate coord)
      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

      private boolean isCovered(Coordinate coord, List geomList)
      Returns:
      true if the coord is located in the interior or boundary of a geometry in the list.
    • computeGeometry

      private Geometry computeGeometry(List resultPointList, List resultLineList, List resultPolyList, int opcode)
    • 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 dimension
      • UNION - result has the dimension of the highest input dimension
      • DIFFERENCE - result has the dimension of the left-hand input
      • SYMDIFFERENCE - 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 performed
      a - an input geometry
      b - an input geometry
      geomFact - the geometry factory being used for the operation
      Returns:
      an empty atomic geometry of the appropriate dimension
    • resultDimension

      private static int resultDimension(int opCode, Geometry g0, Geometry g1)