Class CoverageSimplifier


  • public class CoverageSimplifier
    extends Object
    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).
    This class supports simplification using different distance tolerances for inner and outer edges of the coverage (including no simplfication using a tolerance of 0.0). This allows, for example, inner simplification, which simplifies only edges of the coverage which are adjacent to two polygons. This allows partial simplification of a coverage, since a simplified subset of a coverage still matches the remainder of the coverage.

    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

      Constructors 
      Constructor Description
      CoverageSimplifier​(Geometry[] coverage)
      Create a new coverage simplifier instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void 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[] simplify​(Geometry[] coverage, double tolerance)
      Simplifies the boundaries of a set of polygonal geometries forming a coverage, preserving the coverage topology.
      static Geometry[] simplify​(Geometry[] coverage, double[] tolerances)
      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 Detail

      • CoverageSimplifier

        public CoverageSimplifier​(Geometry[] coverage)
        Create a new coverage simplifier instance.
        Parameters:
        coverage - a set of polygonal geometries forming a coverage
    • Method Detail

      • simplify

        public static Geometry[] simplify​(Geometry[] coverage,
                                          double tolerance)
        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 coverage
        tolerance - the simplification tolerance
        Returns:
        the simplified coverage polygons
      • simplify

        public static Geometry[] simplify​(Geometry[] coverage,
                                          double[] tolerances)
        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 coverage
        tolerance - the simplification tolerances (one per input element)
        Returns:
        the simplified coverage polygons
      • simplifyInner

        public static Geometry[] simplifyInner​(Geometry[] coverage,
                                               double tolerance)
        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 coverage
        tolerance - the simplification tolerance
        Returns:
        the simplified coverage polygons
      • simplifyOuter

        public static Geometry[] simplifyOuter​(Geometry[] coverage,
                                               double tolerance)
        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 coverage
        tolerance - 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

        public Geometry[] simplify​(double tolerance)
        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

        public Geometry[] simplify​(double toleranceInner,
                                   double toleranceOuter)
        Computes the simplified coverage using separate distance tolerances for inner and outer edges, preserving the coverage topology.
        Parameters:
        toleranceInner - the distance tolerance for inner edges
        toleranceOuter - the distance tolerance for outer edges
        Returns:
        the simplified coverage polygons
      • simplify

        public Geometry[] simplify​(double[] tolerances)
        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