Skip to main content

RastaChimp

RastaChimp is a utility library to perform topological processing of polygons vectorized from rasters, as returned by the rasterio.features.shapes function:

  • Simplification, using Douglas-Peucker: Shapely (and GEOS) can be used to simplify polygons but will create gaps and overlaps between polygons that share a boundary (even with preserve_topology=true)
  • Smoothing, using the Chaikin method
  • Densify

RastaChimp decomposes the polygons into edges (using Shapely), applies an operation to them then rebuilds transformed polygons. It works well as long as the output of rasterio.features.shapes is in pixel coordinates (default) or the transform to world coordinates does not have a rotation component, which is usually the case. Because of limited floating precision, it may not work well in the more general case, although it could if the polygons are noded (for example, by using the bpol tool of v.clean in GRASS).

Install

pip install rastachimp

Usage

The function to perform simplification is simplify_dp. As inputs, it takes the tuples (geometry, value) as output from rasterio.features.shapes and the tolerance (in the same unit as the input geometries). It returns an iterator of tuples (geometry, value), just like rasterio.features.shapes.

from rasterio import features
from rastachimp import as_shapely, simplify_dp

# 2D array with classification values
image = np.array(...., dtype=np.uint8)

# no transform => in pixel coordinates
shapes = features.shapes(image)

# convert to Shapely geometry (features.shapes returns a GeoJSON dict)
shapes = as_shapely(shapes)

tolerance = 2
# simpl is an interator of tuples (geometry, value)
simpl = simplify_dp(shapes, tolerance)

Issues

Report issues at https://github.com/gvellut/rastachimp/issues

TODO

  • Better detection and handling of bad inputs
  • Other generalization algorithms (Visvalingam)
  • Other smoothing algorithm (Bezier Curves)

Release files for rastachimp 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rastachimp 0.3
File Size Uploaded
rastachimp-0.3.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rastachimp 0.3
File Interpreter ABI Platform
rastachimp-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / rastachimp-0.3.tar.gz

Download URL rastachimp-0.3.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6962410627b84449ce0e8c1d9be70e1a10767df38e9a9c517d6b232cfaa6a3d1
BLAKE2b-256 checksum
How to use checksums
4ccab9d75e55fe1433b9809787d96bad56c9d11f2dd832f2ad288a0f4a169bcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / rastachimp-0.3-py3-none-any.whl

Download URL rastachimp-0.3-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46fe9f16d357516ece3d4e78c9dccb6442998e623709fbc259ac7525df968e46
BLAKE2b-256 checksum
How to use checksums
0e2b0257507db6973b6affbf8539162868635117da83f181343765c58f83a9aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page