Package org.locationtech.jts.coverage
Class CoverageSimplifier
java.lang.Object
org.locationtech.jts.coverage.CoverageSimplifier
Simplifies the boundaries of the polygons in a polygonal coverage
while preserving the original coverage topology.
An area-based simplification algorithm
(similar to Visvalingam-Whyatt simplification)
is used to provide high-quality results.
Also supports simplifying just the inner edges in a coverage,
which allows simplifying "patches" without affecting their boundary.
The amount of simplification is determined by a tolerance value, which is a non-negative quantity. It equates roughly to the maximum distance by which a simplified line can change from the original. (In fact, it is the square root of the area tolerance used in the Visvalingam-Whyatt algorithm.)
The simplified result coverage has the following characteristics:
- It has the same number of polygonal geometries as the input
- If the input is a valid coverage, then so is the result
- Node points (inner vertices shared by three or more polygons, or boundary vertices shared by two or more) are not changed
- Polygons maintain their line-adjacency (edges are never removed)
- Rings are simplified to a minimum of 4 vertices, to better preserve their shape
- Rings smaller than the area tolerance are removed where possible. This applies to both holes and "islands" (multipolygon elements which are disjoint or touch another polygon at a single vertex). At least one polygon is retained for each input geometry (the one with largest area).
The class allows specifying a separate tolerance for each element of the input coverage.
The input coverage should be valid according to CoverageValidator
.
Invalid coverages may be simplified, but the result will likely still be invalid.
FUTURE WORK
Support geodetic data by computing true geodetic area, and accepting tolerances in metres.- Author:
- Martin Davis
-
Constructor Summary
ConstructorsConstructorDescriptionCoverageSimplifier
(Geometry[] coverage) Create a new coverage simplifier instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
setRemovableRingSizeFactor
(double removableSizeFactor) Sets the factor applied to the area tolerance to determine if small rings should be removed.void
setSmoothWeight
(double smoothWeight) Sets the weight influencing how smooth the simplification should be.Geometry[]
simplify
(double tolerance) Computes the simplified coverage using a single distance tolerance, preserving the coverage topology.Geometry[]
simplify
(double[] tolerances) Computes the simplified coverage using separate distance tolerances for each coverage element, preserving the coverage topology.Geometry[]
simplify
(double toleranceInner, double toleranceOuter) Computes the simplified coverage using separate distance tolerances for inner and outer edges, preserving the coverage topology.static Geometry[]
Simplifies the boundaries of a set of polygonal geometries forming a coverage, preserving the coverage topology.static Geometry[]
Simplifies the boundaries of a set of polygonal geometries forming a coverage, preserving the coverage topology, using a separate tolerance for each element of the coverage.static Geometry[]
simplifyInner
(Geometry[] coverage, double tolerance) Simplifies the inner boundaries of a set of polygonal geometries forming a coverage, preserving the coverage topology.static Geometry[]
simplifyOuter
(Geometry[] coverage, double tolerance) Simplifies the outer boundaries of a set of polygonal geometries forming a coverage, preserving the coverage topology.
-
Constructor Details
-
CoverageSimplifier
Create a new coverage simplifier instance.- Parameters:
coverage
- a set of polygonal geometries forming a coverage
-
-
Method Details
-
simplify
Simplifies the boundaries of a set of polygonal geometries forming a coverage, preserving the coverage topology.- Parameters:
coverage
- a set of polygonal geometries forming a coveragetolerance
- the simplification tolerance- Returns:
- the simplified coverage polygons
-
simplify
Simplifies the boundaries of a set of polygonal geometries forming a coverage, preserving the coverage topology, using a separate tolerance for each element of the coverage. Coverage edges are simplified using the lowest tolerance of each adjacent element.- Parameters:
coverage
- a set of polygonal geometries forming a coveragetolerance
- the simplification tolerances (one per input element)- Returns:
- the simplified coverage polygons
-
simplifyInner
Simplifies the inner boundaries of a set of polygonal geometries forming a coverage, preserving the coverage topology. Edges which form the exterior boundary of the coverage are left unchanged.- Parameters:
coverage
- a set of polygonal geometries forming a coveragetolerance
- the simplification tolerance- Returns:
- the simplified coverage polygons
-
simplifyOuter
Simplifies the outer boundaries of a set of polygonal geometries forming a coverage, preserving the coverage topology. Edges in the interior of the coverage are left unchanged.- Parameters:
coverage
- a set of polygonal geometries forming a coveragetolerance
- the simplification tolerance- Returns:
- the simplified polygons
-
setRemovableRingSizeFactor
public void setRemovableRingSizeFactor(double removableSizeFactor) Sets the factor applied to the area tolerance to determine if small rings should be removed. Larger values cause more rings to be removed. A value of 0 prevents rings from being removed.- Parameters:
removableSizeFactor
- the factor to determine ring size to remove
-
setSmoothWeight
public void setSmoothWeight(double smoothWeight) Sets the weight influencing how smooth the simplification should be. The weight must be between 0 and 1. Larger values increase the smoothness of the simplified edges.- Parameters:
smoothWeight
- a value between 0 and 1
-
simplify
Computes the simplified coverage using a single distance tolerance, preserving the coverage topology.- Parameters:
tolerance
- the simplification distance tolerance- Returns:
- the simplified coverage polygons
-
simplify
Computes the simplified coverage using separate distance tolerances for inner and outer edges, preserving the coverage topology.- Parameters:
toleranceInner
- the distance tolerance for inner edgestoleranceOuter
- the distance tolerance for outer edges- Returns:
- the simplified coverage polygons
-
simplify
Computes the simplified coverage using separate distance tolerances for each coverage element, preserving the coverage topology.- Parameters:
tolerances
- the distance tolerances for the coverage elements- Returns:
- the simplified coverage polygons
-