Fast linestring simplification using RDP or Visvalingam-Whyatt and a Rust binary
Project description
Simplification
Simplify a LineString using the Ramer–Douglas–Peucker or Visvalingam-Whyatt algorithms
Installation
uv add simplification
OR
pip install simplification
OR
conda install conda-forge::simplification
Installing for local development
- Ensure you have a copy of
librdp
from https://github.com/urschrei/rdp/releases, and it's in thesrc/simplification
subdir - run
pip install -e .[test] --use-pep517
- run
pytest .
Supported Python Versions
Simplification supports all currently supported Python versions.
Supported Platforms
- Linux (
manylinux
-compatible) x86_64 and aarch64 - macOS Darwin x86_64 and arm64
- Windows 64-bit
Usage
from simplification.cutil import (
simplify_coords,
simplify_coords_idx,
simplify_coords_vw,
simplify_coords_vw_idx,
simplify_coords_vwp,
)
# Using Ramer–Douglas–Peucker
coords = [
[0.0, 0.0],
[5.0, 4.0],
[11.0, 5.5],
[17.3, 3.2],
[27.8, 0.1]
]
# For RDP, Try an epsilon of 1.0 to start with. Other sensible values include 0.01, 0.001
simplified = simplify_coords(coords, 1.0)
# simplified is [[0.0, 0.0], [5.0, 4.0], [11.0, 5.5], [27.8, 0.1]]
# Using Visvalingam-Whyatt
# You can also pass numpy arrays, in which case you'll get numpy arrays back
import numpy as np
coords_vw = np.array([
[5.0, 2.0],
[3.0, 8.0],
[6.0, 20.0],
[7.0, 25.0],
[10.0, 10.0]
])
simplified_vw = simplify_coords_vw(coords_vw, 30.0)
# simplified_vw is [[5.0, 2.0], [7.0, 25.0], [10.0, 10.0]]
Passing empty and/or 1-element lists will return them unaltered.
But I only want the simplified Indices
simplification
now has:
cutil.simplify_coords_idx
cutil.simplify_coords_vw_idx
The values returned by these functions are the retained indices. In order to use them as e.g. a masked array in Numpy, something like the following will work:
import numpy as np
from simplification.cutil import simplify_coords_idx
# assume an array of coordinates: orig
simplified = simplify_coords_idx(orig, 1.0)
# build new geometry using only retained coordinates
orig_simplified = orig[simplified]
But I need to ensure that the resulting geometries are valid
You 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.
But I Want to Simplify Polylines
No problem; Decode them to LineStrings first.
# pip install pypolyline before you do this
from pypolyline.cutil import decode_polyline
# an iterable of Google-encoded Polylines, so precision is 5. For OSRM &c., it's 6
decoded = (decode_polyline(line, 5) for line in polylines)
simplified = [simplify_coords(line, 1.0) for line in decoded]
How it Works
FFI and a Rust binary
Is It Fast
I should think so.
What does that mean
Using 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.
A larger LineString, containing 200k+ points can be reduced to around 3k points (98.5%+) in around 50ms using RDP.
This is based on a test harness available here.
Disclaimer
All benchmarks are subjective, and pathological input will greatly increase processing time. Error-checking is non-existent at this point.
License
Citing Simplification
If 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):
Hügel, S. (2021). Simplification (Version X.Y.Z) [Computer software]. https://doi.org/10.5281/zenodo.5774852
In Bibtex format:
@software{Hugel_Simplification_2021,
author = {Hügel, Stephan},
doi = {10.5281/zenodo.5774852},
license = {MIT},
month = {12},
title = {{Simplification}},
url = {https://github.com/urschrei/simplification},
version = {X.Y.Z},
year = {2021}
}
Blue Oak Model License
Version 1.0.0
Purpose
This license gives everyone as much permission to work with this software as possible, while protecting contributors from liability.
Acceptance
In order to receive this license, you must agree to its rules. The rules of this license are both obligations under that agreement and conditions to your license. You must not do anything with this software that triggers a rule that you cannot or will not follow.
Copyright
Each contributor licenses you to do everything with this software that would otherwise infringe that contributor's copyright in it.
Notices
You must ensure that everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license or a link to https://blueoakcouncil.org/license/1.0.0.
Excuse
If anyone notifies you in writing that you have not complied with Notices, you can keep your license by taking all practical steps to comply within 30 days after the notice. If you do not do so, your license ends immediately.
Patent
Each contributor licenses you to do everything with this software that would otherwise infringe any patent claims they can license or become able to license.
Reliability
No contributor can revoke this license.
No Liability
As far as the law allows, this software comes as is, without any warranty or condition, and no contributor will be liable to anyone for any damages related to this software or this license, under any kind of legal claim.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for simplification-0.7.13-cp313-cp313-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7092d57248779d86c935763a02084b60c9e3859b1259be75a83b8da662826c8f |
|
MD5 | b4698dcfe9da09662cb30d0945960905 |
|
BLAKE2b-256 | 862e043372c3b5b9b7d2e2ec58c7590e914e411f8e4cabbb2ef52bdc36fa32ec |
Hashes for simplification-0.7.13-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7a9bbab712e9efced43b2808f9fba9b296933faffbf9456e9f3bb081b143e08 |
|
MD5 | 0c46f2b97bd6db4f4ee91e596587343b |
|
BLAKE2b-256 | 9c675a3cc671bfcb5bfaf8484e0d350fb6da17367471f736f0249b88199a2e79 |
Hashes for simplification-0.7.13-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c02278b3bcdccbf315c31be6332b62f8be2971910a862cc95771542eb8389bd |
|
MD5 | 2eb36b51f6f917eb9539c131bac4e663 |
|
BLAKE2b-256 | 2559dd25b36659eb55ea5eb994bfa56098d38ca95bbc4aafc0eba6ef345ad0c2 |
Hashes for simplification-0.7.13-cp313-cp313-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60364a6b9ef2c561dd6b057ce1455e30d772b588b3d07e98bcedec830a307858 |
|
MD5 | b3a79c8b203ff47594f8e6cfd8bbc239 |
|
BLAKE2b-256 | c1593aeeb1d39017331bef275007f10fa62044767fa685f5381d01a06668b202 |
Hashes for simplification-0.7.13-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eda0cb08a5f6cc90b48014833f1dd603c7435dc81e6316f61b288806c84c31bf |
|
MD5 | f6c760a44d356dc1cc6fa265ed8f7d62 |
|
BLAKE2b-256 | a8684238606b2ec0bc3b713b98d1f260b0631f6139f4499de5e5e3ab430eea7c |
Hashes for simplification-0.7.13-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 599a1e5d05d474d14f5859764bb98f9ee2d8ff156420b22eca6c8635159cba2c |
|
MD5 | f4304d5e87256597591f6c701ff21d7c |
|
BLAKE2b-256 | b6876f1d6339d8279ef55ab38811742f99b0596287fe0d8b0e033149c8d9bd6b |
Hashes for simplification-0.7.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5127aa72369111f27783311d806ba62452065fb9a06f7445514dbe093c6885c1 |
|
MD5 | c288b4eab77f0c9ce50fb9886b783dec |
|
BLAKE2b-256 | 723183f133dd919ee05972f3b1a9dc7217b9d69eac580443383f946a5b52628d |
Hashes for simplification-0.7.13-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14b3a49957370b509d781583fad0fab169d6c60418393d0aab365c25c301c00e |
|
MD5 | 03ec9045c2c2793ff351881b10507445 |
|
BLAKE2b-256 | 7ee17add2d7ee952a52939279f064dce7835661833ebff50674c1a13f660e685 |
Hashes for simplification-0.7.13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7a2e32abe44f84e891b47523b142b9fd29fefadacc3850f94324315bb340a99 |
|
MD5 | 149d1824ed3eabf3614ff77825dee445 |
|
BLAKE2b-256 | 2bf45a62d228a86b6365abce1d8b75e02fcd01addb34ed2d311048f42f8764ff |
Hashes for simplification-0.7.13-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3fb9b94003e28bbc84f71b0d7f1f56936ee9c3c536d7dbfd21ed6bc68810a8d |
|
MD5 | 346e97ed6d296011d340bc6de5fd0555 |
|
BLAKE2b-256 | 00809496018dc63d79eb1c4a345ced5fad38b87c4c04ed1241a0676b3c574931 |
Hashes for simplification-0.7.13-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d28b080ae0b3255906a1f8fc0bd14ce7d99c46ebbdea352f574cd3a010f8fb7 |
|
MD5 | 62af73371400e2cf58253fb4759e751f |
|
BLAKE2b-256 | 2517653d9cfb57068ac11060b82d6c2a6e1db20ea731f2910e48cac3da16ec96 |
Hashes for simplification-0.7.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6f2130789e4726f7ce73a3043bed9980ca504824c3ecb2001123543ea295085 |
|
MD5 | aa0addd5b4b266507b824f7439ff1f17 |
|
BLAKE2b-256 | 35e1fe91971f897ffa835a3228eea4d95622fb92bbcccf38c414913d42445cb7 |
Hashes for simplification-0.7.13-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f5888544c489a9ed897d62f28e5465a60c3eba9e9ff07e13b78c1da92c5d7d0 |
|
MD5 | a6e8de5bb731ac8905e3ed0459b61f08 |
|
BLAKE2b-256 | 8647cd04b263e575b00a19ed85cf86cfa3247e4a435ff35c90683e57f92cf0f9 |
Hashes for simplification-0.7.13-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 338723ab18d2150af74369e74e9b09024acd9700c405f7d72bb0f53b1e36da50 |
|
MD5 | 65a636130a7ff5909434cb69d8fc74c1 |
|
BLAKE2b-256 | 0f7fe2c1a8d50efad3c3574da251f9d9717e2cf506442deb9cc1af1048446b7d |
Hashes for simplification-0.7.13-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d0b4f6e678bbd693268155b3b24d1d26a81b3fcff57eacbaa0fcbea7328e33b |
|
MD5 | a0d4ce6f76addb9ec355b689c75f4f69 |
|
BLAKE2b-256 | 6ed033f719701fbac841359b62006067d7438589c86831dc87fdc6d2baf0f624 |
Hashes for simplification-0.7.13-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0e71474728ebe3da7cc68d5048e9a1ef9903afbafe2b9c7664e76e99019a555 |
|
MD5 | ddea262f72928426b53dd4ddcce7908c |
|
BLAKE2b-256 | 2f01b3280a62f61025f113b80aa1af9dbc63a4507fed4c0672704faa15567793 |
Hashes for simplification-0.7.13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81d39241b85e63db951061c6b272de4efd0b4b74e1aa4ccdb530c201d262cb97 |
|
MD5 | e084dbda1e56f2f01fd1a01cba737ef5 |
|
BLAKE2b-256 | ddf4a6aaae28bc0f8e24e9564b19bab0b202e9cdac1fd2b37b3b5096486fad0b |
Hashes for simplification-0.7.13-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d102769132ab409140816671e53972a35f5d870f7233da991db1c3023b081450 |
|
MD5 | 7c411d30eba82831dfc9276cea6f9ef2 |
|
BLAKE2b-256 | c65481de1ce9c9bc463578d3a7e4c7717fa1399efdd4e4ae79f56a1cca2fecf9 |
Hashes for simplification-0.7.13-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2b540af7ef90a721c1966abd35a661a0ba9cb57221289ed502ae9580f863690 |
|
MD5 | c62df21bd6d3438b1b7288c3a3f7d24d |
|
BLAKE2b-256 | 651e48ffbe7dd17916f09d4a1a2664feda5859c0c0c148f85602048ba9a9fc7d |
Hashes for simplification-0.7.13-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bde7771fcfbc30a3fd9fc731b04924521e9ecdab65631c3b398e659a9a7aa8d0 |
|
MD5 | 18a0d563bf9c8239c1c32ae447ddeb59 |
|
BLAKE2b-256 | 8b22978f55b4ebbac244222d85508880bedeca7361c0060f064264bee70802b9 |
Hashes for simplification-0.7.13-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afc74d7863ffee44ceb7bc8e9bce2ad3a4778e10e4a3874ae05f35b39af08566 |
|
MD5 | 3e84690da9b838733acc93015e712e90 |
|
BLAKE2b-256 | c59d13d8287c21836656da73f28649a34efba2e1084bf0ff0dc893cc446e078f |
Hashes for simplification-0.7.13-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fb7cfe26ea343c99efe874be0444c8d08572127d574f3f5dd055f3f78fac82a |
|
MD5 | 6ec66027c8ed4990a05ccfc41f810a68 |
|
BLAKE2b-256 | a45bdbee0dd8ef2af9b4b5cf79be5c8166b0421a604342cb3031ac7e39c726fd |
Hashes for simplification-0.7.13-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aa8c0852c04690c946d38992227b68109bab25d5de6fe8618141a56ca5a9c9b |
|
MD5 | c819f1d0900b8ff01cb64cff71cc9527 |
|
BLAKE2b-256 | 2fd968b22713eab7bacde8920ca04936d67c73d8e603fedb24096aa49aab4ec3 |
Hashes for simplification-0.7.13-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d85e61727166b295dd58cb65ccf74e3fc5f983412c58d3b1182a011ba6f857a |
|
MD5 | 6c383e9607f73ab2104d3cc40854a458 |
|
BLAKE2b-256 | 1e50601656ab66a1b8af6edbc5841d2244594e7b661c836c0102fc6624475dd0 |