{"id":13564271,"url":"https://github.com/urschrei/simplification","last_synced_at":"2025-05-15T18:04:21.578Z","repository":{"id":10281116,"uuid":"65199659","full_name":"urschrei/simplification","owner":"urschrei","description":"Very fast Python line simplification using either the RDP or Visvalingam-Whyatt algorithm implemented in Rust","archived":false,"fork":false,"pushed_at":"2024-10-14T05:05:55.000Z","size":3808,"stargazers_count":170,"open_issues_count":3,"forks_count":18,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-30T08:18:22.319Z","etag":null,"topics":["computational-geometry","geo","geospatial","linestring","polyline","rdp","simplification","visvalingam-whyatt"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/urschrei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-08T11:42:49.000Z","updated_at":"2024-10-14T05:05:56.000Z","dependencies_parsed_at":"2024-01-14T03:51:40.508Z","dependency_job_id":"eb633cca-e477-4121-a90d-f3456d1684b6","html_url":"https://github.com/urschrei/simplification","commit_stats":{"total_commits":453,"total_committers":10,"mean_commits":45.3,"dds":0.4415011037527594,"last_synced_commit":"91c728af9e91084066095ffa636ab01e30340886"},"previous_names":[],"tags_count":80,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urschrei%2Fsimplification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urschrei%2Fsimplification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urschrei%2Fsimplification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urschrei%2Fsimplification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/urschrei","download_url":"https://codeload.github.com/urschrei/simplification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744332,"owners_count":20988783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computational-geometry","geo","geospatial","linestring","polyline","rdp","simplification","visvalingam-whyatt"],"created_at":"2024-08-01T13:01:29.016Z","updated_at":"2025-04-07T23:07:48.144Z","avatar_url":"https://github.com/urschrei.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"[![Build Status](https://github.com/urschrei/simplification/actions/workflows/wheels.yml/badge.svg)](https://github.com/urschrei/simplification/actions/workflows/wheels.yml) [![Coverage Status](https://coveralls.io/repos/github/urschrei/simplification/badge.svg?branch=master)](https://coveralls.io/github/urschrei/simplification?branch=master) [![Downloads](https://pepy.tech/badge/simplification)](https://pepy.tech/project/simplification) [![DOI](https://zenodo.org/badge/65199659.svg)](https://zenodo.org/badge/latestdoi/65199659) [![Anaconda-Server Badge](https://anaconda.org/conda-forge/simplification/badges/version.svg)](https://anaconda.org/conda-forge/simplification)\n\n# Simplification\nSimplify a LineString using the [Ramer–Douglas–Peucker](https://en.wikipedia.org/wiki/Ramer–Douglas–Peucker_algorithm) or [Visvalingam-Whyatt](https://bost.ocks.org/mike/simplify/) algorithms\n\n![Line](https://cdn.rawgit.com/urschrei/rdp/6c84264fd9cdc0b8fdf974fc98e51fea4834ed05/rdp.svg)  \n\n## Installation\n`uv add simplification` OR  \n`pip install simplification` OR  \n`conda install conda-forge::simplification`\n\n### Installing for local development\n1. Ensure you have a copy of `librdp` from https://github.com/urschrei/rdp/releases, and it's in the `src/simplification` subdir\n2. run `pip install -e .[test] --use-pep517`\n3. run `pytest .`\n\n### Supported Python Versions\nSimplification supports all [_currently_ supported Python versions](https://devguide.python.org/versions/).\n\n### Supported Platforms\n- Linux (`manylinux`-compatible) x86_64 and aarch64\n- macOS Darwin x86_64 and arm64\n- Windows 64-bit\n\n## Usage\n```python\nfrom simplification.cutil import (\n    simplify_coords,\n    simplify_coords_idx,\n    simplify_coords_vw,\n    simplify_coords_vw_idx,\n    simplify_coords_vwp,\n)\n\n# Using Ramer–Douglas–Peucker\ncoords = [\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]\n\n# For RDP, Try an epsilon of 1.0 to start with. Other sensible values include 0.01, 0.001\nsimplified = simplify_coords(coords, 1.0)\n\n# simplified is [[0.0, 0.0], [5.0, 4.0], [11.0, 5.5], [27.8, 0.1]]\n\n# Using Visvalingam-Whyatt\n# You can also pass numpy arrays, in which case you'll get numpy arrays back\nimport numpy as np\ncoords_vw = np.array([\n    [5.0, 2.0],\n    [3.0, 8.0],\n    [6.0, 20.0],\n    [7.0, 25.0],\n    [10.0, 10.0]\n])\nsimplified_vw = simplify_coords_vw(coords_vw, 30.0)\n\n# simplified_vw is [[5.0, 2.0], [7.0, 25.0], [10.0, 10.0]]\n```\n\nPassing empty and/or 1-element lists will return them unaltered.\n\n## But I only want the simplified **Indices**\n`simplification` now has:\n\n- `cutil.simplify_coords_idx`\n- `cutil.simplify_coords_vw_idx`\n\nThe values returned by these functions are the **retained** indices. In order to use them as e.g. a [masked array](https://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html#what-is-a-masked-array) in Numpy, something like the following will work:\n\n    import numpy as np\n    from simplification.cutil import simplify_coords_idx\n\n    # assume an array of coordinates: orig\n    simplified = simplify_coords_idx(orig, 1.0)\n    # build new geometry using only retained coordinates\n    orig_simplified = orig[simplified]\n\n\n## But I need to ensure that the resulting geometries are valid\nYou can use the topology-preserving variant of `VW` for this: `simplify_coords_vwp`. It's slower, but has a far greater likelihood of producing a valid geometry.\n\n\n## But I Want to Simplify Polylines\nNo problem; [Decode them to LineStrings](https://github.com/urschrei/pypolyline) first.\n\n``` python\n# pip install pypolyline before you do this\nfrom pypolyline.cutil import decode_polyline\n# an iterable of Google-encoded Polylines, so precision is 5. For OSRM \u0026c., it's 6\ndecoded = (decode_polyline(line, 5) for line in polylines)\nsimplified = [simplify_coords(line, 1.0) for line in decoded]\n```\n\n## How it Works\nFFI and a [Rust binary](https://github.com/urschrei/rdp)\n\n## Is It Fast\nI should think so.\n### What does that mean\nUsing `numpy` arrays for input and output, the library can be reasonably expected to process around 2500 1000-point LineStrings per second on a Core i7 or equivalent, for a 98%+ reduction in size.  \nA larger LineString, containing 200k+ points can be reduced to around 3k points (98.5%+) in around 50ms using RDP.\n\nThis is based on a test harness available [here](benchmark_runner.py).\n#### Disclaimer\nAll benchmarks are subjective, and pathological input will greatly increase processing time. Error-checking is non-existent at this point.\n\n## License\n[Blue Oak Model Licence 1.0.0](LICENSE.md)\n\n## Citing `Simplification`\nIf Simplification has been significant in your research, and you would like to acknowledge the project in your academic publication, we suggest citing it as follows (example in APA style, 7th edition):\n\n\u003e Hügel, S. (2021). Simplification (Version X.Y.Z) [Computer software]. https://doi.org/10.5281/zenodo.5774852\n\nIn Bibtex format:\n\n    @software{Hugel_Simplification_2021,\n    author = {Hügel, Stephan},\n    doi = {10.5281/zenodo.5774852},\n    license = {MIT},\n    month = {12},\n    title = {{Simplification}},\n    url = {https://github.com/urschrei/simplification},\n    version = {X.Y.Z},\n    year = {2021}\n    }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furschrei%2Fsimplification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Furschrei%2Fsimplification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furschrei%2Fsimplification/lists"}