Class Polygonizer


  • public class Polygonizer
    extends java.lang.Object
    Polygonizes a set of Geometrys which contain linework that represents the edges of a planar graph. All types of Geometry are accepted as input; the constituent linework is extracted as the edges to be polygonized. The processed edges must be correctly noded; that is, they must only meet at their endpoints. Polygonization will accept incorrectly noded input but will not form polygons from non-noded edges, and reports them as errors.

    The Polygonizer reports the follow kinds of errors:

    • Dangles - edges which have one or both ends which are not incident on another edge endpoint
    • Cut Edges - edges which are connected at both ends but which do not form part of polygon
    • Invalid Ring Lines - edges which form rings which are invalid (e.g. the component lines contain a self-intersection)
    Polygonization supports extracting only polygons which form a valid polygonal geometry. The set of extracted polygons is guaranteed to be edge-disjoint. This is useful for situations where it is known that the input lines form a valid polygonal geometry.
    Version:
    1.7
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Polygonizer.LineStringAdder
      Adds every linear element in a Geometry into the polygonizer graph.
    • Constructor Summary

      Constructors 
      Constructor Description
      Polygonizer()
      Creates a polygonizer with the same GeometryFactory as the input Geometrys.
      Polygonizer​(boolean extractOnlyPolygonal)
      Creates a polygonizer and allow specifying if only polygons which form a valid polygonal geometry are to be extracted.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.util.Collection geomList)
      Adds a collection of geometries to the edges to be polygonized.
      void add​(Geometry g)
      Add a Geometry to the edges to be polygonized.
      private void add​(LineString line)
      Adds a linestring to the graph of polygon edges.
      private static void assignHolesToShells​(java.util.List holeList, java.util.List shellList)  
      private static void assignHoleToShell​(EdgeRing holeER, java.util.List shellList)  
      private static java.util.List extractPolygons​(java.util.List shellList, boolean includeAll)  
      private static void findDisjointShells​(java.util.List shellList)  
      private static void findOuterShells​(java.util.List shellList)
      For each outer hole finds and includes a single outer shell.
      private void findShellsAndHoles​(java.util.List edgeRingList)  
      private void findValidRings​(java.util.List edgeRingList, java.util.List validEdgeRingList, java.util.List invalidRingList)  
      java.util.Collection getCutEdges()
      Gets the list of cut edges found during polygonization.
      java.util.Collection getDangles()
      Gets the list of dangling lines found during polygonization.
      Geometry getGeometry()
      Gets a geometry representing the polygons formed by the polygonization.
      java.util.Collection getInvalidRingLines()
      Gets the list of lines forming invalid rings found during polygonization.
      java.util.Collection getPolygons()
      Gets the list of polygons formed by the polygonization.
      private void polygonize()
      Performs the polygonization, if it has not already been carried out.
      void setCheckRingsValid​(boolean isCheckingRingsValid)
      Allows disabling the valid ring checking, to optimize situations where invalid rings are not expected.
      • Methods inherited from class java.lang.Object

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

      • dangles

        protected java.util.Collection dangles
      • cutEdges

        protected java.util.List cutEdges
      • invalidRingLines

        protected java.util.List invalidRingLines
      • holeList

        protected java.util.List holeList
      • shellList

        protected java.util.List shellList
      • polyList

        protected java.util.List polyList
      • isCheckingRingsValid

        private boolean isCheckingRingsValid
      • extractOnlyPolygonal

        private boolean extractOnlyPolygonal
    • Constructor Detail

      • Polygonizer

        public Polygonizer()
        Creates a polygonizer with the same GeometryFactory as the input Geometrys. The output mask is #ALL_POLYS.
      • Polygonizer

        public Polygonizer​(boolean extractOnlyPolygonal)
        Creates a polygonizer and allow specifying if only polygons which form a valid polygonal geometry are to be extracted.
        Parameters:
        extractOnlyPolygonal - true if only polygons which form a valid polygonal geometry are to be extracted
    • Method Detail

      • add

        public void add​(java.util.Collection geomList)
        Adds a collection of geometries to the edges to be polygonized. May be called multiple times. Any dimension of Geometry may be added; the constituent linework will be extracted and used.
        Parameters:
        geomList - a list of Geometrys with linework to be polygonized
      • add

        public void add​(Geometry g)
        Add a Geometry to the edges to be polygonized. May be called multiple times. Any dimension of Geometry may be added; the constituent linework will be extracted and used
        Parameters:
        g - a Geometry with linework to be polygonized
      • add

        private void add​(LineString line)
        Adds a linestring to the graph of polygon edges.
        Parameters:
        line - the LineString to add
      • setCheckRingsValid

        public void setCheckRingsValid​(boolean isCheckingRingsValid)
        Allows disabling the valid ring checking, to optimize situations where invalid rings are not expected.

        The default is true.

        Parameters:
        isCheckingRingsValid - true if generated rings should be checked for validity
      • getPolygons

        public java.util.Collection getPolygons()
        Gets the list of polygons formed by the polygonization.
        Returns:
        a collection of Polygons
      • getGeometry

        public Geometry getGeometry()
        Gets a geometry representing the polygons formed by the polygonization. If a valid polygonal geometry was extracted the result is a Polygonal geometry.
        Returns:
        a geometry containing the polygons
      • getDangles

        public java.util.Collection getDangles()
        Gets the list of dangling lines found during polygonization.
        Returns:
        a collection of the input LineStrings which are dangles
      • getCutEdges

        public java.util.Collection getCutEdges()
        Gets the list of cut edges found during polygonization.
        Returns:
        a collection of the input LineStrings which are cut edges
      • getInvalidRingLines

        public java.util.Collection getInvalidRingLines()
        Gets the list of lines forming invalid rings found during polygonization.
        Returns:
        a collection of the input LineStrings which form invalid rings
      • polygonize

        private void polygonize()
        Performs the polygonization, if it has not already been carried out.
      • findValidRings

        private void findValidRings​(java.util.List edgeRingList,
                                    java.util.List validEdgeRingList,
                                    java.util.List invalidRingList)
      • findShellsAndHoles

        private void findShellsAndHoles​(java.util.List edgeRingList)
      • assignHolesToShells

        private static void assignHolesToShells​(java.util.List holeList,
                                                java.util.List shellList)
      • assignHoleToShell

        private static void assignHoleToShell​(EdgeRing holeER,
                                              java.util.List shellList)
      • findDisjointShells

        private static void findDisjointShells​(java.util.List shellList)
      • findOuterShells

        private static void findOuterShells​(java.util.List shellList)
        For each outer hole finds and includes a single outer shell. This seeds the traversal algorithm for finding only polygonal shells.
        Parameters:
        shellList - the list of shell EdgeRings
      • extractPolygons

        private static java.util.List extractPolygons​(java.util.List shellList,
                                                      boolean includeAll)