RDPpy
Implementation of the Ramer-Douglas-Peucker algorithm for polylines using a point-to-line-segment distance measure.
Usage
The API consists of a single function rdppy.filter(points, threshold) which returns a binary mask upon calling with a sequence of points and a threshold (aka the epsilon value):
>>> import rdppy
>>> points = [(0, 0),
... (4, 0),
... (0, 1),
... (1, 1),
... (1, 2),
... (2, 2),
... (2, 3),
... (3, 3),
... (3, 4),
... (5, 4)]
>>> mask = rdppy.filter(points, threshold=.9)
>>> mask
array([True, True, True, False, False, False, False, False, True, True])
This mask is a numpy array and can be used to filter a given sequence, e.g.,
>>> import numpy as np
>>> np.array(points)[mask]
array([[0, 0],
[4, 0],
[0, 1],
[3, 4],
[5, 4]])
Note that this allows the filtering of more complex sequences which carry, for instance, meta information:
>>> points = np.array([(0, 0, 'a'),
... (4, 0, 'b'),
... (0, 1, 'c'),
... (1, 1, 'd'),
... (1, 2, 'e'),
... (2, 2, 'f'),
... (2, 3, 'g'),
... (3, 3, 'h'),
... (3, 4, 'i'),
... (5, 4, 'j')])
>>> mask = rdppy.filter([(float(x), float(y)) for x, y, _ in points], .9)
>>> points[mask, -1]
array(['a', 'b', 'c', 'i', 'j'], dtype='<U21')
The default metric only works for 2D points but users may define custom metrics to measure the distance between a list of points, points, of any dimension and a segment parametrized via its start, seg_start, and end seg_end. For instance my_dist2 measures the distances of 2D points to the (infinite) line rather than the finite segment:
>>> def my_dist2(points, seg_start, seg_end):
... d = np.divide(seg_end - seg_start, np.sqrt(np.sum((seg_end - seg_start) ** 2)))
... return np.cross(points - np.expand_dims(seg_start, 0), np.expand_dims(d, 0)) ** 2
>>> rdppy.filter(points, threshold=.9, dist2_fun=my_dist2)
The maximum of the returned values is compared with the squared threshold value. By default the function rdp.dist2 is used:
rdppy.filter(points, threshold, dist2_fun=rdppy.rdp.dist2)
Metadata
Release files for rdppy 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rdppy-0.0.2.tar.gz | 4.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rdppy-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.2 kB
Release files / rdppy-0.0.2.tar.gz
| Download URL | rdppy-0.0.2.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d84fd29e60522136e37e297cd43d8a6882449b9501f7585d98e9087120e84981
|
|
BLAKE2b-256 checksum How to use checksums |
294f3ba4d7765ced021831aa2e5d9880a04b87a0d8a3875ede000d09b86ac60e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Release files / rdppy-0.0.2-py3-none-any.whl
| Download URL | rdppy-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
291ffdda0df135e3e14c849883ae26f34f1b44f5443845e932d013b6b34c9385
|
|
BLAKE2b-256 checksum How to use checksums |
48e380054a887807604e5434ad1e4ce9ae69b6eec8bb0021764ce4c95ce36100
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Security for rdppy 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.