Class PolygonBuilder

java.lang.Object
org.locationtech.jts.operation.overlay.PolygonBuilder

public class PolygonBuilder extends Object
Forms Polygons out of a graph of DirectedEdges. The edges to use are marked as being in the result Area.

Version:
1.7
  • Field Details

  • Constructor Details

  • Method Details

    • add

      public void add(PlanarGraph graph)
      Add a complete graph. The graph is assumed to contain one or more polygons, possibly with holes.
    • add

      public void add(Collection dirEdges, Collection nodes)
      Add a set of edges and nodes, which form a graph. The graph is assumed to contain one or more polygons, possibly with holes.
    • getPolygons

      public List getPolygons()
    • buildMaximalEdgeRings

      private List buildMaximalEdgeRings(Collection dirEdges)
      for all DirectedEdges in result, form them into MaximalEdgeRings
    • buildMinimalEdgeRings

      private List buildMinimalEdgeRings(List maxEdgeRings, List shellList, List freeHoleList)
    • findShell

      private EdgeRing findShell(List minEdgeRings)
      This method takes a list of MinimalEdgeRings derived from a MaximalEdgeRing, and tests whether they form a Polygon. This is the case if there is a single shell in the list. In this case the shell is returned. The other possibility is that they are a series of connected holes, in which case no shell is returned.
      Returns:
      the shell EdgeRing, if there is one or null, if all the rings are holes
    • placePolygonHoles

      private void placePolygonHoles(EdgeRing shell, List minEdgeRings)
      This method assigns the holes for a Polygon (formed from a list of MinimalEdgeRings) to its shell. Determining the holes for a MinimalEdgeRing polygon serves two purposes:
      • it is faster than using a point-in-polygon check later on.
      • it ensures correctness, since if the PIP test was used the point chosen might lie on the shell, which might return an incorrect result from the PIP test
    • sortShellsAndHoles

      private void sortShellsAndHoles(List edgeRings, List shellList, List freeHoleList)
      For all rings in the input list, determine whether the ring is a shell or a hole and add it to the appropriate list. Due to the way the DirectedEdges were linked, a ring is a shell if it is oriented CW, a hole otherwise.
    • placeFreeHoles

      private void placeFreeHoles(List shellList, List freeHoleList)
      This method determines finds a containing shell for all holes which have not yet been assigned to a shell. These "free" holes should all be properly contained in their parent shells, so it is safe to use the findEdgeRingContaining method. (This is the case because any holes which are NOT properly contained (i.e. are connected to their parent shell) would have formed part of a MaximalEdgeRing and been handled in a previous step).
      Throws:
      TopologyException - if a hole cannot be assigned to a shell
    • findEdgeRingContaining

      private EdgeRing findEdgeRingContaining(EdgeRing testEr, List shellList)
      Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any. The innermost enclosing ring is the smallest enclosing ring. The algorithm used depends on the fact that:
      ring A contains ring B iff envelope(ring A) contains envelope(ring B)
      This routine is only safe to use if the chosen point of the hole is known to be properly contained in a shell (which is guaranteed to be the case if the hole does not touch its shell)
      Returns:
      containing EdgeRing, if there is one or null if no containing EdgeRing is found
    • computePolygons

      private List computePolygons(List shellList)
    • containsPoint

      public boolean containsPoint(Coordinate p)
      Checks the current set of shells (with their associated holes) to see if any of them contain the point.