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.3.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

visvalingamwyatt-0.3.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: visvalingamwyatt-0.3.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for visvalingamwyatt-0.3.0.tar.gz
Algorithm Hash digest
SHA256 517399516b11474615d987515c76e00592f6672dc018c4799e7cc37e6d53e3b7
MD5 1850af14b7e89f006647c3f032c456db
BLAKE2b-256 6c0d2468d8bd948b4b2ae7d2f5d6d859d217de1dd19bf9b579c631711a8136d5

See more details on using hashes here.

File details

Details for the file visvalingamwyatt-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for visvalingamwyatt-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5db733dcda754aae3f2bba04b2ead8f0e3c0e30f65f3fae2c9d9d6c1295e017
MD5 5a950a0e88449adde3d1fd709470b6e4
BLAKE2b-256 d949911423a0fce38bc719dc394d2b10ff8bd6d38af6462fb89b86ff94c35c1c

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