Skip to main content

Module simplify

Module simplify 

Source
Expand description

Douglas-Peucker line simplification.

Classic recursive algorithm: keep the two endpoints; find the vertex farthest from the chord between them; if its perpendicular distance is above tolerance, keep it and recurse on both halves; otherwise discard all intermediate vertices.

Complexity is O(n²) worst case, O(n log n) typical. Tolerances are in the same units as the input coordinates — pass degree-based tolerances for lng/lat data, meter-based for projected data.

Functions§

douglas_peucker
Simplify a polyline (or polygon ring without its closing duplicate) using Douglas-Peucker. Always preserves the first and last coords.
simplify_geometry
Apply Douglas-Peucker to every linear part of a Geometry. Polygon rings are kept closed (the closing duplicate is restored if simplification dropped it). Point / MultiPoint / Empty pass through unchanged.
tolerance_for_zoom
A small preset tolerance (in degrees) for typical web-map zoom levels.