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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: visvalingamwyatt-0.2.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for visvalingamwyatt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5e1e3ca7c329eb27073950cf15ed300c62b7650adccb00ceecf1efc8723162de
MD5 915225da88eab7936c5be736f8fda376
BLAKE2b-256 6ff3feea4fc41bbe6113e6de5836cf255266ce22937bf95445f72d862dda2968

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visvalingamwyatt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for visvalingamwyatt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8aeb040e82ebc8b0cfeed6b60b9398d7667fa870ed0b8cac0890a99b4200ea12
MD5 18e6d9da0388547e451e2f96a9c22f77
BLAKE2b-256 04e9dc4c255442387bd8ab6198aaf9d7454adb39c008e5946f33d859f23633f7

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