simplifyPolyline
Removes the points of a polyline that change its shape by less than tolerance, with the
Ramer–Douglas–Peucker algorithm: each removed point is at most tolerance away from the
simplified line. It shrinks map outlines or traced paths by orders of magnitude while keeping
their look.
The first and last points are always kept. With a tolerance of 0, only points exactly on a
straight line are removed. It is iterative, so very long polylines do not overflow the stack.
Available since v3.1.5
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
points | readonly Point[] | The polyline |
tolerance | number | The maximum distance between a removed point and the result, in the units of the points |
Returns
Section titled “Returns”Point[] — The kept points, in their original order
Examples
Section titled “Examples”Drop a nearly straight point
Section titled “Drop a nearly straight point”A point closer than the tolerance to the simplified line is removed.
Shrink a map outline
Section titled “Shrink a map outline”Pick the tolerance in the units of the points, e.g. a fraction of a pixel at the final scale.
Related Types
Section titled “Related Types”A point in 2D space.
