public class Polygonizer
extends java.lang.Object
Geometry
s 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:
Modifier and Type | Class and Description |
---|---|
private static class |
Polygonizer.LineStringAdder
Adds every linear element in a
Geometry into the polygonizer graph. |
Modifier and Type | Field and Description |
---|---|
protected java.util.List |
cutEdges |
protected java.util.Collection |
dangles |
private boolean |
extractOnlyPolygonal |
private GeometryFactory |
geomFactory |
protected PolygonizeGraph |
graph |
protected java.util.List |
holeList |
protected java.util.List |
invalidRingLines |
private boolean |
isCheckingRingsValid |
private Polygonizer.LineStringAdder |
lineStringAdder |
protected java.util.List |
polyList |
protected java.util.List |
shellList |
Constructor and Description |
---|
Polygonizer()
Creates a polygonizer with the same
GeometryFactory
as the input Geometry s. |
Polygonizer(boolean extractOnlyPolygonal)
Creates a polygonizer and allow specifying if only polygons which form a valid polygonal geometry are to be extracted.
|
Modifier and Type | Method and 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.
|
private Polygonizer.LineStringAdder lineStringAdder
protected PolygonizeGraph graph
protected java.util.Collection dangles
protected java.util.List cutEdges
protected java.util.List invalidRingLines
protected java.util.List holeList
protected java.util.List shellList
protected java.util.List polyList
private boolean isCheckingRingsValid
private boolean extractOnlyPolygonal
private GeometryFactory geomFactory
public Polygonizer()
GeometryFactory
as the input Geometry
s.
The output mask is #ALL_POLYS
.public Polygonizer(boolean extractOnlyPolygonal)
extractOnlyPolygonal
- true if only polygons which form a valid polygonal geometry are to be extractedpublic void add(java.util.Collection geomList)
geomList
- a list of Geometry
s with linework to be polygonizedpublic void add(Geometry g)
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 usedg
- a Geometry
with linework to be polygonizedprivate void add(LineString line)
line
- the LineString
to addpublic void setCheckRingsValid(boolean isCheckingRingsValid)
The default is true
.
isCheckingRingsValid
- true if generated rings should be checked for validitypublic java.util.Collection getPolygons()
Polygon
spublic Geometry getGeometry()
Polygonal
geometry.public java.util.Collection getDangles()
LineString
s which are danglespublic java.util.Collection getCutEdges()
LineString
s which are cut edgespublic java.util.Collection getInvalidRingLines()
LineString
s which form invalid ringsprivate void polygonize()
private void findValidRings(java.util.List edgeRingList, java.util.List validEdgeRingList, java.util.List invalidRingList)
private void findShellsAndHoles(java.util.List edgeRingList)
private static void assignHolesToShells(java.util.List holeList, java.util.List shellList)
private static void assignHoleToShell(EdgeRing holeER, java.util.List shellList)
private static void findDisjointShells(java.util.List shellList)
private static void findOuterShells(java.util.List shellList)
shellList
- the list of shell EdgeRingsprivate static java.util.List extractPolygons(java.util.List shellList, boolean includeAll)