{"id":7719,"library":"simplification","title":"Fast Linestring Simplification","description":"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.","status":"active","version":"0.7.14","language":"en","source_language":"en","source_url":"https://github.com/urschrei/simplification","tags":["geometry","gis","linestring","polyline","simplification","RDP","Visvalingam-Whyatt","Rust","geospatial"],"install":[{"cmd":"pip install simplification","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Requires Python 3.10 or newer.","package":"python","optional":false},{"reason":"Highly recommended for efficient input/output of coordinate arrays.","package":"numpy","optional":true}],"imports":[{"note":"Primary function for Ramer-Douglas-Peucker simplification.","symbol":"simplify_coords","correct":"from simplification.cutil import simplify_coords"},{"note":"Primary function for Visvalingam-Whyatt simplification.","symbol":"simplify_coords_vw","correct":"from simplification.cutil import simplify_coords_vw"},{"note":"Topology-preserving variant of Visvalingam-Whyatt, which is slower but more likely to produce valid geometries.","symbol":"simplify_coords_vwp","correct":"from simplification.cutil import simplify_coords_vwp"}],"quickstart":{"code":"import numpy as np\nfrom simplification.cutil import simplify_coords, simplify_coords_vw\n\n# Example coordinates (list of lists or NumPy array)\ncoords_list = [\n    [0.0, 0.0],\n    [5.0, 4.0],\n    [11.0, 5.5],\n    [17.3, 3.2],\n    [27.8, 0.1]\n]\ncoords_np = np.array(coords_list)\n\n# --- Ramer-Douglas-Peucker (RDP) Simplification ---\n# Epsilon: maximum distance between an original point and the simplified line segment\nepsilon_rdp = 1.0\nsimplified_rdp = simplify_coords(coords_list, epsilon_rdp)\nprint(f\"RDP Simplified (epsilon={epsilon_rdp}): {simplified_rdp}\")\n\n# --- Visvalingam-Whyatt (VW) Simplification ---\n# Threshold: minimum effective area of a triangle formed by a point and its neighbors\nthreshold_vw = 30.0\nsimplified_vw = simplify_coords_vw(coords_np, threshold_vw)\nprint(f\"VW Simplified (threshold={threshold_vw}): {simplified_vw}\")","lang":"python","description":"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."},"warnings":[{"fix":"Always import specific simplification functions from `simplification.cutil`, e.g., `from simplification.cutil import simplify_coords`.","message":"The library primarily exposes functions through `simplification.cutil`, which is a Cython/Rust FFI module. Direct imports from `simplification` (e.g., `from simplification import simplify`) will fail as the main simplification functions are not exposed at the top-level package.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Thoroughly validate input data (coordinate types and structure) before passing it to simplification functions to prevent runtime errors.","message":"The library's documentation explicitly states that 'Error-checking is non-existent at this point.' This means invalid inputs (e.g., non-numeric coordinates, malformed lists) might lead to crashes or unexpected behavior rather than clear Python exceptions.","severity":"gotcha","affected_versions":"All versions (v0.7.14 and earlier)"},{"fix":"Understand the trade-offs: use `simplify_coords_vw` for maximum speed if topological correctness is secondary; use `simplify_coords_vwp` when preserving topology is critical, accepting a performance cost.","message":"When using Visvalingam-Whyatt, the `simplify_coords_vwp` function offers a topology-preserving variant. While it produces geometries less prone to self-intersections, it is generally slower than `simplify_coords_vw`. Choose based on your application's need for speed versus geometric validity.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For local development from source, ensure Rust (cargo) is installed. If encountering installation issues in constrained environments, verify that pre-built wheels are available for your platform and Python version, or prepare to compile from source.","message":"The `simplification` library relies on a compiled Rust binary. While `pip install` typically handles pre-built wheels, local development or unusual environments might require a Rust toolchain for compilation, which can be a dependency hurdle.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `pip install simplification` completes without errors. If installing in a non-standard environment or from source, you may need a Rust toolchain installed (e.g., `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`) and potentially development headers for Python.","cause":"The `simplification` library's core functions are implemented in Rust and exposed via a `cutil` module. This error usually means the C/Rust extension module failed to compile or was not properly installed.","error":"ModuleNotFoundError: No module named 'simplification.cutil'"},{"fix":"Correct the import statement to specifically target `simplification.cutil`: `from simplification.cutil import simplify_coords` (or other relevant functions).","cause":"Attempting to import simplification functions directly from the top-level `simplification` package instead of its `cutil` submodule.","error":"AttributeError: module 'simplification' has no attribute 'simplify_coords'"},{"fix":"Ensure your input coordinates are a sequence of sequences (e.g., `[[x1, y1], [x2, y2]]`) or a 2D NumPy array with shape `(N, 2)` or `(N, 3)` where N is the number of points and 2/3 are the dimensions.","cause":"The input `coords` argument to `simplify_coords` or `simplify_coords_vw` is not in the expected format (e.g., not a list of lists/tuples of numbers, or a 2D NumPy array).","error":"ValueError: input is not a valid sequence of coordinates"}]}