Class Polygonizer
java.lang.Object
org.locationtech.jts.operation.polygonize.Polygonizer
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)
- Version:
- 1.7
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classAdds every linear element in aGeometryinto the polygonizer graph. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Listprotected Collectionprivate booleanprivate GeometryFactoryprotected PolygonizeGraphprotected Listprotected Listprivate booleanprivate Polygonizer.LineStringAdderprotected Listprotected List -
Constructor Summary
ConstructorsConstructorDescriptionCreates a polygonizer with the sameGeometryFactoryas the inputGeometrys.Polygonizer(boolean extractOnlyPolygonal) Creates a polygonizer and allow specifying if only polygons which form a valid polygonal geometry are to be extracted. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Collection geomList) Adds a collection of geometries to the edges to be polygonized.voidAdd aGeometryto the edges to be polygonized.private voidadd(LineString line) Adds a linestring to the graph of polygon edges.private static voidassignHolesToShells(List holeList, List shellList) private static voidassignHoleToShell(EdgeRing holeER, List shellList) private static ListextractPolygons(List shellList, boolean includeAll) private static voidfindDisjointShells(List shellList) private static voidfindOuterShells(List shellList) For each outer hole finds and includes a single outer shell.private voidfindShellsAndHoles(List edgeRingList) private voidfindValidRings(List edgeRingList, List validEdgeRingList, List invalidRingList) Gets the list of cut edges found during polygonization.Gets the list of dangling lines found during polygonization.Gets a geometry representing the polygons formed by the polygonization.Gets the list of lines forming invalid rings found during polygonization.Gets the list of polygons formed by the polygonization.private voidPerforms the polygonization, if it has not already been carried out.voidsetCheckRingsValid(boolean isCheckingRingsValid) Allows disabling the valid ring checking, to optimize situations where invalid rings are not expected.
-
Field Details
-
lineStringAdder
-
graph
-
dangles
-
cutEdges
-
invalidRingLines
-
holeList
-
shellList
-
polyList
-
isCheckingRingsValid
private boolean isCheckingRingsValid -
extractOnlyPolygonal
private boolean extractOnlyPolygonal -
geomFactory
-
-
Constructor Details
-
Polygonizer
public Polygonizer()Creates a polygonizer with the sameGeometryFactoryas the inputGeometrys. The output mask is.invalid reference
#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 Details
-
add
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 ofGeometrys with linework to be polygonized
-
add
Add aGeometryto 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- aGeometrywith linework to be polygonized
-
add
Adds a linestring to the graph of polygon edges.- Parameters:
line- theLineStringto 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
Gets the list of polygons formed by the polygonization.- Returns:
- a collection of
Polygons
-
getGeometry
Gets a geometry representing the polygons formed by the polygonization. If a valid polygonal geometry was extracted the result is ageometry.invalid reference
Polygonal- Returns:
- a geometry containing the polygons
-
getDangles
Gets the list of dangling lines found during polygonization.- Returns:
- a collection of the input
LineStrings which are dangles
-
getCutEdges
Gets the list of cut edges found during polygonization.- Returns:
- a collection of the input
LineStrings which are cut edges
-
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
-
findShellsAndHoles
-
assignHolesToShells
-
assignHoleToShell
-
findDisjointShells
-
findOuterShells
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
-