Skip to main content

Fast linestring simplification using RDP or Visvalingam-Whyatt and a Rust binary

Project description

Build Status Coverage Status Downloads DOI Anaconda-Server Badge

Simplification

Simplify a LineString using the Ramer–Douglas–Peucker or Visvalingam-Whyatt algorithms

Line

Installation

uv add simplification OR
pip install simplification OR
conda install conda-forge::simplification

Installing for local development

  1. Ensure you have a copy of librdp and header.h from https://github.com/urschrei/rdp/releases, and it's in the src/simplification subdir
  2. run uv sync --dev
  3. run pytest .

Changes in pyx and pxd files, and the Rust library and header will bust the cache, triggering a rebuild when uv commands are run.

Building SDist and Wheels

  1. Ensure that librdp and header are present, as above
  2. Run uv build --sdist --wheel

Supported Python Versions

Simplification supports all currently supported Python versions.

Binary wheels target the CPython Stable ABI (abi3): a single abi3 wheel per platform covers CPython 3.11 and later, while CPython 3.10 receives a standard version-specific wheel.

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

Blue Oak Model Licence 1.0.0

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}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplification-1.0.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

simplification-1.0.0-cp311-abi3-win_amd64.whl (333.4 kB view details)

Uploaded CPython 3.11+Windows x86-64

simplification-1.0.0-cp311-abi3-manylinux_2_28_x86_64.whl (290.1 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

simplification-1.0.0-cp311-abi3-manylinux_2_28_aarch64.whl (274.5 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

simplification-1.0.0-cp311-abi3-macosx_11_0_x86_64.whl (261.1 kB view details)

Uploaded CPython 3.11+macOS 11.0+ x86-64

simplification-1.0.0-cp311-abi3-macosx_11_0_arm64.whl (243.2 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

simplification-1.0.0-cp310-cp310-win_amd64.whl (341.9 kB view details)

Uploaded CPython 3.10Windows x86-64

simplification-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl (299.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

simplification-1.0.0-cp310-cp310-manylinux_2_28_aarch64.whl (283.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

simplification-1.0.0-cp310-cp310-macosx_11_0_x86_64.whl (269.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

simplification-1.0.0-cp310-cp310-macosx_11_0_arm64.whl (251.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file simplification-1.0.0.tar.gz.

File metadata

  • Download URL: simplification-1.0.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for simplification-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c1e33379455f5da02462b2d674b816a5f385bbbde216652101465fd33e4a2e3c
MD5 93e9d18195e26df175a069c53098e3c9
BLAKE2b-256 ede4acaf8400d85ced98c4a371818fcde69c202fdbd3942666e374989cb370be

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0.tar.gz:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e114c5feaa44fa6272dbf2a455f901b9c6196fb653b45652db0741c0770fe154
MD5 f4a5a0a52f67bb9119efdb8cac44e995
BLAKE2b-256 2f6708db7eabb5f2fb74702ec5b478a0c206177d68d9875a7b13c3b8bbda15b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp311-abi3-win_amd64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e533dd74ee873728de1eda7a456c2ebd021243137c59c5c674e5d9665b930d22
MD5 6f8f5c85ef7b8915d6b8baa8a5d97c03
BLAKE2b-256 691c083b6a0d5909741620581f6730f23357ca308bc6fb33823d35b9be9587cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp311-abi3-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 249ec6b7bbf2baed3655246dde003a9607ae7cb182e7c7053ada52c01ceef808
MD5 8b79e7b2fd77476f248a532eb82c4fda
BLAKE2b-256 097a55f40b9a903bf45ac24da8bb4f2fbc3419c80462e6c43dd6b5713d53383c

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp311-abi3-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp311-abi3-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp311-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 4e0fa16ea12cdce014d0cf649a36bf91733bddbfab8e6fd7bab7251bbd5c28f1
MD5 497cceb3e2afbb6b12094ce96edbf184
BLAKE2b-256 f42eb0a647c7757b432dbc2a5b84ae49c8e01a8a78380442d3d67b1352e2f141

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp311-abi3-macosx_11_0_x86_64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8def6393614096bfcb69e889f0da371a58009de8fc3d6660e31dfda3d0f35e61
MD5 0e8f168fec2982bcdb18f2c6e33772e7
BLAKE2b-256 54a438cfcf4d209748ad543b8fde594f66513227fb74b0840cceba0192ef3ded

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 07f59a2497caa598cf2b9788d07c4dc4451741dc4516caf3678307947eb64d75
MD5 ade33630839a1239d93d41b9bd4d6faf
BLAKE2b-256 f1418c87aed926a38f0d76403a0127c087942b85fbb71f72fcd84844b353f974

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp310-cp310-win_amd64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 28f3217807ff37484d7f8a9a31dd49ea6b767198af3f147b72627dd6101b2c1d
MD5 31138db6ddc7d80d03da85e71258a48f
BLAKE2b-256 dc0e96186c48fcf1ca4759a49df80d7e3c720f0e008d4cd3fab003319ea10ec3

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 475d31233860a9e583a07697bc09857ce8baf28a82a58adcb35f51ae9ec24de4
MD5 ae4de1abdc73e14df4bc85a2d370457e
BLAKE2b-256 19523cdb0b78eebf7409744daa3b79fc08bd5e2a63b85e80227a67b44e91cb9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 b7ab0bc7b00a89cbb03fa2940ddbe9d20e1e51830989efe9a45453a76d72d330
MD5 09ecaf6a3692281509c3020598edd6e1
BLAKE2b-256 658115e3ff65c77998720cab86324d3282cb7c8ade14b1a9a969e6667a61b61e

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp310-cp310-macosx_11_0_x86_64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplification-1.0.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for simplification-1.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a828ebd3d1f086fd8219f09f01cc979e947994cd473901a48ba5eb922e0d23ec
MD5 722553da574f0831c908e63ec834dc08
BLAKE2b-256 f6e94862674a2e8aa98265e18a75af9bde4796fb67905ca80dd1d0dafdb5c6cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplification-1.0.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheels.yml on urschrei/simplification

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page