Simplify geometries with the Visvalingam-Wyatt algorithm
Project description
A Python implementation of the Visvalingam-Wyatt line simplification algorithm.
This implementation is due to Eliot Hallmark. This release simply packages it as a Python module.
Use
>>> import visvalingamwyatt as vw
>>> points = [(1, 2), (2, 3), (3, 4), ...]
>>> vw.simplify(points)
[(1, 2), (3, 4), ...]
Points may be any Sequence-like object that (list, tuple, a custom class that exposes an __iter__ method).
Test different methods and thresholds:
simplifier = vw.Simplifier(points)
# Simplify by percentage of points to keep
simplifier.simplify(ratio=0.5)
# Simplify by giving number of points to keep
simplifier.simplify(number=1000)
# Simplify by giving an area threshold
simplifier.simplify(threshold=0.01)
Shorthands for working with geodata:
import visvalingamwyatt as vw
feature = {
"properties": {"foo": "bar"},
"geometry": {
"type": "Polygon",
"coordinates": [...]
}
}
# returns a copy of the geometry, simplified (keeping 90% of points)
vw.simplify_geometry(feature['geometry'], ratio=0.90)
# returns a copy of the feature, simplified (using an area threshold)
vw.simplify_feature(feature, threshold=0.90)
The command line tool vwsimplify is available to simplify GeoJSON files:
# Simplify using a ratio of points vwsimplify --ratio 0.90 in.geojson -o simple.geojson # Simplify using the number of points to keep vwsimplify --number 1000 in.geojson -o simple.geojson # Simplify using a minimum area vwsimplify --threshold 0.001 in.geojson -o simple.geojson
Install Fiona for the additional ability to simplify any geodata layer.
License
MIT
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
Built Distribution
File details
Details for the file visvalingamwyatt-0.1.2.tar.gz
.
File metadata
- Download URL: visvalingamwyatt-0.1.2.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e0098841854f96179b215c2cda5bfed47d02eedc0c9a7954309057507b39c2a |
|
MD5 | 6c3509d3f7cc7380bd6da3e98d2e86f9 |
|
BLAKE2b-256 | 8f16aeb01de587a538d0b4228d3b0654365084e406ca370bd2b428b0ce716bba |
File details
Details for the file visvalingamwyatt-0.1.2-py2.py3-none-any.whl
.
File metadata
- Download URL: visvalingamwyatt-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6866ddec26dca4d7c9cc18687cdab10fbfe8bf004a9277a14951e8b294489bf |
|
MD5 | 170e150c71c805df3a9bcd0198279277 |
|
BLAKE2b-256 | 0d45938a471cdd3ca65abb2eb1f1b5f8fda219c10cbebd6ce15084bdb4437480 |