Fast Linestring Simplification

0.7.14 · active · verified Thu Apr 16

The `simplification` library provides highly optimized linestring (polyline) simplification using either the Ramer-Douglas-Peucker (RDP) or Visvalingam-Whyatt algorithms. It achieves high performance by leveraging a Rust binary through Python's Foreign Function Interface (FFI). The library is currently at version 0.7.14 and appears to be actively maintained with frequent minor releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to simplify a linestring using both the Ramer-Douglas-Peucker (RDP) and Visvalingam-Whyatt (VW) algorithms. It showcases usage with both standard Python lists of coordinates and NumPy arrays, which are efficiently handled by the underlying Rust implementation. For RDP, `epsilon` defines the tolerance, while for VW, `threshold` represents a minimum effective area.

import numpy as np
from simplification.cutil import simplify_coords, simplify_coords_vw

# Example coordinates (list of lists or NumPy array)
coords_list = [
    [0.0, 0.0],
    [5.0, 4.0],
    [11.0, 5.5],
    [17.3, 3.2],
    [27.8, 0.1]
]
coords_np = np.array(coords_list)

# --- Ramer-Douglas-Peucker (RDP) Simplification ---
# Epsilon: maximum distance between an original point and the simplified line segment
epsilon_rdp = 1.0
simplified_rdp = simplify_coords(coords_list, epsilon_rdp)
print(f"RDP Simplified (epsilon={epsilon_rdp}): {simplified_rdp}")

# --- Visvalingam-Whyatt (VW) Simplification ---
# Threshold: minimum effective area of a triangle formed by a point and its neighbors
threshold_vw = 30.0
simplified_vw = simplify_coords_vw(coords_np, threshold_vw)
print(f"VW Simplified (threshold={threshold_vw}): {simplified_vw}")

view raw JSON →