Class TopologyPreservingSimplifier


  • public class TopologyPreservingSimplifier
    extends java.lang.Object
    Simplifies a geometry and ensures that the result is a valid geometry having the same dimension and number of components as the input, and with the components having the same topological relationship.

    If the input is a polygonal geometry ( Polygon or MultiPolygon ):

    • The result has the same number of shells and holes as the input, with the same topological structure
    • The result rings touch at no more than the number of touching points in the input (although they may touch at fewer points). The key implication of this statement is that if the input is topologically valid, so is the simplified output.
    For linear geometries, if the input does not contain any intersecting line segments, this property will be preserved in the output.

    For all geometry types, the result will contain enough vertices to ensure validity. For polygons and closed linear geometries, the result will have at least 4 vertices; for open linestrings the result will have at least 2 vertices.

    All geometry types are handled. Empty and point geometries are returned unchanged. Empty geometry components are deleted.

    The simplification uses a maximum-distance difference algorithm similar to the Douglas-Peucker algorithm.

    KNOWN BUGS

    • May create invalid topology if there are components which are small relative to the tolerance value. In particular, if a small hole is very near an edge, it is possible for the edge to be moved by a relatively large tolerance value and end up with the hole outside the result shell (or inside another hole). Similarly, it is possible for a small polygon component to end up inside a nearby larger polygon. A workaround is to test for this situation in post-processing and remove any invalid holes or polygons.
    Author:
    Martin Davis
    See Also:
    DouglasPeuckerSimplifier
    • Constructor Detail

      • TopologyPreservingSimplifier

        public TopologyPreservingSimplifier​(Geometry inputGeom)
    • Method Detail

      • simplify

        public static Geometry simplify​(Geometry geom,
                                        double distanceTolerance)
      • setDistanceTolerance

        public void setDistanceTolerance​(double distanceTolerance)
        Sets the distance tolerance for the simplification. All vertices in the simplified geometry will be within this distance of the original geometry. The tolerance value must be non-negative. A tolerance value of zero is effectively a no-op.
        Parameters:
        distanceTolerance - the approximation tolerance to use
      • getResultGeometry

        public Geometry getResultGeometry()