Skip to main content

C++/pybind11/NumPy implementation of the Ramer-Douglas-Peucker algorithm (Ramer 1972; Douglas and Peucker 1973) for 2D and 3D data.

Project description

Ramer-Douglas-Peucker Algorithm (c++ binding for python via pybind11)

A speed up (~8000x) version of python version of rdp.

C++/pybind11/NumPy implementation of the Ramer-Douglas-Peucker algorithm (Ramer 1972; Douglas and Peucker 1973) for 2D and 3D data.

The Ramer-Douglas-Peucker algorithm is an algorithm for reducing the number of points in a curve that is approximated by a series of points.

Installation

via pip

pip install -U pybind11-rdp

from source

git clone --recursive https://github.com/cubao/pybind11-rdp
pip install ./pybind11-rdp

Or

pip install git+https://github.com/cubao/pybind11-rdp.git

(you can build wheels for later reuse by pip wheel git+https://github.com/cubao/pybind11-rdp.git)

Usage

Test installation: python -c 'from pybind11_rdp import rdp; print(rdp([[1, 1], [2, 2], [3, 3], [4, 4]]))'

Simple pythonic interface:

from pybind11_rdp import rdp

rdp([[1, 1], [2, 2], [3, 3], [4, 4]])
[[1, 1], [4, 4]]

With epsilon=0.5:

rdp([[1, 1], [1, 1.1], [2, 2]], epsilon=0.5)
[[1.0, 1.0], [2.0, 2.0]]

Numpy interface:

import numpy as np
from pybind11_rdp import rdp

rdp(np.array([1, 1, 2, 2, 3, 3, 4, 4]).reshape(4, 2))
array([[1, 1],
       [4, 4]])

Tests

make python_install
make python_test

Notice

As https://github.com/fhirschmann/rdp/issues/13 points out, pdist in rdp is WRONGLY Point-to-Line distance. We use Point-to-LineSegment distance.

from rdp import rdp
print(rdp([[0, 0], [10, 0.1], [1, 0]], epsilon=1.0)) # wrong
# [[0.0, 0.0],
#  [1.0, 0.0]]

from pybind11_rdp import rdp
print(rdp([[0, 0], [10, 0.1], [1, 0]], epsilon=1.0)) # correct
# [[ 0.   0. ]
#  [10.   0.1]
#  [ 1.   0. ]]

References

Douglas, David H, and Thomas K Peucker. 1973. “Algorithms for the Reduction of the Number of Points Required to Represent a Digitized Line or Its Caricature.” Cartographica: The International Journal for Geographic Information and Geovisualization 10 (2): 112–122.

Ramer, Urs. 1972. “An Iterative Procedure for the Polygonal Approximation of Plane Curves.” Computer Graphics and Image Processing 1 (3): 244–256.

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

pybind11_rdp-0.1.4.tar.gz (2.8 MB view hashes)

Uploaded Source

Built Distributions

pybind11_rdp-0.1.4-cp311-cp311-win_amd64.whl (78.7 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pybind11_rdp-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (96.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pybind11_rdp-0.1.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (90.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pybind11_rdp-0.1.4-cp311-cp311-macosx_11_0_arm64.whl (66.6 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pybind11_rdp-0.1.4-cp311-cp311-macosx_10_9_x86_64.whl (72.8 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pybind11_rdp-0.1.4-cp310-cp310-win_amd64.whl (78.7 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pybind11_rdp-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (96.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pybind11_rdp-0.1.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (90.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pybind11_rdp-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (66.6 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pybind11_rdp-0.1.4-cp310-cp310-macosx_10_9_x86_64.whl (72.8 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pybind11_rdp-0.1.4-cp39-cp39-win_amd64.whl (78.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pybind11_rdp-0.1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (96.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pybind11_rdp-0.1.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (90.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pybind11_rdp-0.1.4-cp39-cp39-macosx_11_0_arm64.whl (66.7 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pybind11_rdp-0.1.4-cp39-cp39-macosx_10_9_x86_64.whl (72.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pybind11_rdp-0.1.4-cp38-cp38-win_amd64.whl (78.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pybind11_rdp-0.1.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (95.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pybind11_rdp-0.1.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (90.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pybind11_rdp-0.1.4-cp38-cp38-macosx_11_0_arm64.whl (66.5 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pybind11_rdp-0.1.4-cp38-cp38-macosx_10_9_x86_64.whl (72.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pybind11_rdp-0.1.4-cp37-cp37m-win_amd64.whl (78.4 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

pybind11_rdp-0.1.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (98.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pybind11_rdp-0.1.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (94.0 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

pybind11_rdp-0.1.4-cp37-cp37m-macosx_10_9_x86_64.whl (72.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pybind11_rdp-0.1.4-cp36-cp36m-win_amd64.whl (78.4 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

pybind11_rdp-0.1.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (98.5 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

pybind11_rdp-0.1.4-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (93.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

pybind11_rdp-0.1.4-cp36-cp36m-macosx_10_9_x86_64.whl (72.3 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

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