Class PolygonBuilder


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

    Version:
    1.7
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.util.Collection dirEdges, java.util.Collection nodes)
      Add a set of edges and nodes, which form a graph.
      void add​(PlanarGraph graph)
      Add a complete graph.
      private java.util.List buildMaximalEdgeRings​(java.util.Collection dirEdges)
      for all DirectedEdges in result, form them into MaximalEdgeRings
      private java.util.List buildMinimalEdgeRings​(java.util.List maxEdgeRings, java.util.List shellList, java.util.List freeHoleList)  
      private java.util.List computePolygons​(java.util.List shellList)  
      boolean containsPoint​(Coordinate p)
      Checks the current set of shells (with their associated holes) to see if any of them contain the point.
      private EdgeRing findEdgeRingContaining​(EdgeRing testEr, java.util.List shellList)
      Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any.
      private EdgeRing findShell​(java.util.List minEdgeRings)
      This method takes a list of MinimalEdgeRings derived from a MaximalEdgeRing, and tests whether they form a Polygon.
      java.util.List getPolygons()  
      private void placeFreeHoles​(java.util.List shellList, java.util.List freeHoleList)
      This method determines finds a containing shell for all holes which have not yet been assigned to a shell.
      private void placePolygonHoles​(EdgeRing shell, java.util.List minEdgeRings)
      This method assigns the holes for a Polygon (formed from a list of MinimalEdgeRings) to its shell.
      private void sortShellsAndHoles​(java.util.List edgeRings, java.util.List shellList, java.util.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • shellList

        private java.util.List shellList
    • Constructor Detail

      • PolygonBuilder

        public PolygonBuilder​(GeometryFactory geometryFactory)
    • Method Detail

      • 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​(java.util.Collection dirEdges,
                        java.util.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 java.util.List getPolygons()
      • buildMaximalEdgeRings

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

        private java.util.List buildMinimalEdgeRings​(java.util.List maxEdgeRings,
                                                     java.util.List shellList,
                                                     java.util.List freeHoleList)
      • findShell

        private EdgeRing findShell​(java.util.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,
                                       java.util.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​(java.util.List edgeRings,
                                        java.util.List shellList,
                                        java.util.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​(java.util.List shellList,
                                    java.util.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,
                                                java.util.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 java.util.List computePolygons​(java.util.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.