Skip to main content

Simplify geometries with the Visvalingam-Wyatt algorithm

Project description

Visvalingam-Wyatt

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 (in the units of the data)
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

visvalingamwyatt-0.1.4.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

visvalingamwyatt-0.1.4-py2.py3-none-any.whl (15.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file visvalingamwyatt-0.1.4.tar.gz.

File metadata

  • Download URL: visvalingamwyatt-0.1.4.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for visvalingamwyatt-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ca3131e8a87d46da39d001ad7a8179c393940db8b441886104f99ad85f15475b
MD5 762187c5791f3c32f5a61f6b09d9fb8b
BLAKE2b-256 1e3d39f1034787b81c6470192e7565f3c90debcdeb2be6875fb1ba8c11d06e1b

See more details on using hashes here.

File details

Details for the file visvalingamwyatt-0.1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: visvalingamwyatt-0.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for visvalingamwyatt-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8c431d0177768bcd4231fe92683d7f6c40dd88e4f64f5992cd2f33dbb7946723
MD5 f38c9aceec41c6c761420347362cfa34
BLAKE2b-256 d49ca0a8158d41f8b721074e861a946f0487e4abe2935848b151dceb38876b79

See more details on using hashes here.

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