Skip to main content

contourrs

contourrs — a coral contour island inside a charcoal outline

PyPI DOI

contourrs converts NumPy rasters into polygons with a Rust core and Python bindings. Use it to trace land-cover classes and segmentation masks, or extract filled contour bands from elevation and probability grids. The Python package requires no GDAL installation.

Documentation · API reference · PyPI · Benchmarks

Install

pip install contourrs

Wheels are available for Python 3.12–3.14 on Linux (x86_64 and ARM64), macOS (Apple Silicon), and Windows (x86_64). NumPy and PyArrow are installed as dependencies.

Polygonize a raster

Each connected region of equal-valued pixels becomes a polygon.

import numpy as np
from contourrs import shapes

labels = np.array([[1, 1, 2], [1, 2, 2], [3, 3, 3]], dtype=np.uint8)

for geometry, value in shapes(labels, connectivity=4):
    print(value, geometry["type"])
# 1.0 Polygon
# 2.0 Polygon
# 3.0 Polygon

Use connectivity=8 to join regions that touch diagonally. Like rasterio.features.shapes, each result pairs a GeoJSON geometry dictionary with its raster value. shapes() returns a list rather than an iterator.

USDA Cropland Data Layer raster and extracted polygons

A 512 × 512 crop of the 2023 USDA Cropland Data Layer for Polk County, Iowa. The right panel shows polygons extracted in tiles and merged across tile boundaries.

Export to Arrow and GeoParquet

The Arrow variants return a pyarrow.Table with a WKB geometry column and a float64 value column. They avoid constructing a Python geometry dictionary for every polygon and transfer buffers through the Arrow C Data Interface without copying them.

import pyarrow.parquet as pq
from contourrs import shapes_arrow

table = shapes_arrow(labels, connectivity=4)
pq.write_table(table, "polygons.parquet")

The table includes GeoParquet metadata. An affine transform sets output coordinates, but the CRS remains unknown until you assign it; see georeferenced export.

Extract contour bands

contours() interpolates boundaries between raster samples and returns filled polygons between consecutive thresholds. Each result's value is the lower threshold of its band.

import numpy as np
from contourrs import contours

axis = np.linspace(-2, 2, 128)
x, y = np.meshgrid(axis, axis)
elevation = np.exp(-(x**2 + y**2))

bands = contours(elevation, thresholds=[0.1, 0.3, 0.5, 0.7, 1.0])

This extracts the bands [0.1, 0.3), [0.3, 0.5), [0.5, 0.7), and [0.7, 1.0). Values outside those intervals are excluded.

A synthetic elevation field and its interpolated contour bands

Interpolated bands from a synthetic terrain with three peaks. The raster and filled bands share a color scale; white areas fall below the first threshold.

Both operations offer the same two output formats:

Input GeoJSON geometry/value pairs Arrow table
Categorical raster shapes() shapes_arrow()
Continuous raster contours() contours_arrow()

Masks and map coordinates

All four functions accept mask, nodata, and transform:

from contourrs import shapes_arrow

table = shapes_arrow(
    labels,
    nodata=0,
    transform=(10, 0, 500000, 0, -10, 4500000),
)
  • True entries in mask include samples. Use nodata=0 to exclude zeros or nodata=np.nan to exclude NaNs.
  • transform accepts an affine.Affine or the six coefficients (a, b, c, d, e, f) used by rasterio.
  • Inputs and masks must be two-dimensional and C-contiguous. Use np.ascontiguousarray() after slicing or transposing when needed.
  • Accepted dtypes are uint8, uint16, uint32, int16, int32, float32, and float64.

Polygonization follows pixel edges; contours interpolate between samples at integer (column, row) coordinates. See the coordinate conventions when applying a raster transform. Read raster files with rasterio or another loader, then pass the arrays to contourrs.

Tutorials

Notebook sources are in examples/. Performance notes describe the benchmark inputs, output costs, and memory measurements.

Development

Install uv and Rust, then:

git clone https://github.com/taylor-geospatial/contourrs.git
cd contourrs
make install
make test
make check

Run make build after changing Rust code. The checks include Rust formatting and Clippy, Ruff, ty, Pyrefly, and the Rust test suite. make test also runs the Python tests, including comparisons against rasterio. See development and docs setup and the Rust architecture for more.

License

Apache-2.0.

Citation

Cite the v0.8.1 Zenodo archive:

@software{isaac_corley_2026_22949666,
  author       = {Isaac Corley},
  title        = {isaaccorley/contourrs: v0.8.1},
  month        = sep,
  year         = 2026,
  publisher    = {Zenodo},
  version      = {v0.8.1},
  doi          = {10.5281/zenodo.22949666},
  url          = {https://doi.org/10.5281/zenodo.22949666},
}

Metadata

Release files for contourrs 0.8.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 contourrs 0.8.3
File Size Uploaded Provenance Actions
contourrs-0.8.3.tar.gz 49.9 kB With provenance Details for contourrs-0.8.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for contourrs 0.8.3
File Actions
contourrs-0.8.3-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for contourrs-0.8.3-cp314-cp314-win_amd64.whl
contourrs-0.8.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details for contourrs-0.8.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
contourrs-0.8.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ ARM64 Details for contourrs-0.8.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
contourrs-0.8.3-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for contourrs-0.8.3-cp314-cp314-macosx_11_0_arm64.whl
contourrs-0.8.3-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for contourrs-0.8.3-cp313-cp313-win_amd64.whl
contourrs-0.8.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for contourrs-0.8.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
contourrs-0.8.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ ARM64 Details for contourrs-0.8.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
contourrs-0.8.3-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for contourrs-0.8.3-cp313-cp313-macosx_11_0_arm64.whl
contourrs-0.8.3-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for contourrs-0.8.3-cp312-cp312-win_amd64.whl
contourrs-0.8.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for contourrs-0.8.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
contourrs-0.8.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ ARM64 Details for contourrs-0.8.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
contourrs-0.8.3-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for contourrs-0.8.3-cp312-cp312-macosx_11_0_arm64.whl

Total release size: 9.4 MB

Release files / contourrs-0.8.3.tar.gz

Download URL contourrs-0.8.3.tar.gz
Size 49.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4ad9791bf9fcf26d1f16d534caa3fd972665f3cf6772fde4f0033d0a17250373
BLAKE2b-256 checksum
How to use checksums
7bb62a26e7facf2f7f3435bae59174606159b729871e5b164558d9061bd63e31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp314-cp314-win_amd64.whl

Download URL contourrs-0.8.3-cp314-cp314-win_amd64.whl
Size 591.6 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
3556e788bb3bc4504f8f1b294ff2fa6f94030dc82425f46da7450145ef96e755
BLAKE2b-256 checksum
How to use checksums
e45ffc4b77d7511069d04685eff8960c167278456e59e88be9420ed16802e397
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL contourrs-0.8.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.0 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9000c50cefb0fcba5dda16147f03678d0c89b955239af066c5528eff73a47a01
BLAKE2b-256 checksum
How to use checksums
a3eae642f1f3daf484af51f5aa7844d9edfdff7c090b797851e7e87ab71b31c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL contourrs-0.8.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 794.6 kB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
cc8fa3f875de5b770727d5f044d295ca2041706918b3da3f9862cc380332a4af
BLAKE2b-256 checksum
How to use checksums
75246d1f2be4e3aaf11f2d5d3da4985738b9faf266f3c6015b44409fea8e1cfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp314-cp314-macosx_11_0_arm64.whl

Download URL contourrs-0.8.3-cp314-cp314-macosx_11_0_arm64.whl
Size 706.8 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
56432c1a8c474533dd63d9cab83f8f51ad06708ca61c33acaee4c9542842084c
BLAKE2b-256 checksum
How to use checksums
c10be0f3c730550b81558b9bcf5e647f92484a095c14ef75b0cd3216258c9398
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp313-cp313-win_amd64.whl

Download URL contourrs-0.8.3-cp313-cp313-win_amd64.whl
Size 594.5 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
b68305623474911d75f9d54e44e494fbc7d999f9b1a99ebb48113364412770f6
BLAKE2b-256 checksum
How to use checksums
c70967ec5e7ef8179b2ff8f730fb7fad3cf1c157b8324eb78494d41f0e32d57d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL contourrs-0.8.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.0 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b5c088a299aa1e1be80438a90055f45fb546ebc2a566e0b097b3059d1a0637af
BLAKE2b-256 checksum
How to use checksums
ab12c19a63aa45417daa2f3c3c3d044fdd366b85d711fd084e46d47335ba3cea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL contourrs-0.8.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 795.1 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
762d46d994ea6b638675663c79523495a625c3261911136b9d2db5e2fc6c5ebb
BLAKE2b-256 checksum
How to use checksums
9319f47e246ccb0553e345e807e13d8bf4f87fc38091c7c2e6320a8e98d656ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp313-cp313-macosx_11_0_arm64.whl

Download URL contourrs-0.8.3-cp313-cp313-macosx_11_0_arm64.whl
Size 704.2 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
63b880e5a4ca80ee1cb79df9011dea262016913ed1f56bee20f2a144f4e241cd
BLAKE2b-256 checksum
How to use checksums
c1ee3e12ffcd0c189ea02c8441b6204d107940ba58a41c7e3270ff2fcc52c1b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp312-cp312-win_amd64.whl

Download URL contourrs-0.8.3-cp312-cp312-win_amd64.whl
Size 594.6 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
c7170ab5224000ad585f169d8c9e1a2ca477eea3dade685231801f7b9fc0fde5
BLAKE2b-256 checksum
How to use checksums
9f1b0cdc50503a6401b6a7e548b1ee296f3e6094fe47a913996ab7a8b48de1b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL contourrs-0.8.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.0 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a2f8a90a55884b25641963d7bcce271968ee2ee100a954508242a928aee5305a
BLAKE2b-256 checksum
How to use checksums
83222bff6b42f4602c009f87a2858ad58f3c6caf71926d46f55ecfde7fbd9c46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL contourrs-0.8.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 793.6 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
cad71ee6ed5179344af6f037f353dfc39cd734395c1fbe332eca973b3bb34b7d
BLAKE2b-256 checksum
How to use checksums
ab501a2c2b9e511bb37f02b5d8b694e99ee4772e8f54fa43ee002e09b21cd432
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / contourrs-0.8.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL contourrs-0.8.3-cp312-cp312-macosx_11_0_arm64.whl
Size 703.0 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
62e5f07bb660a89ea2a32c49ccdd7120ef99a8e3dfeb806ae83ead13f2a51f56
BLAKE2b-256 checksum
How to use checksums
bddbffc10a02850b97ff549167e458da88d0a7463b238a256ffa16a030d074b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for contourrs 0.8.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 13 files in this release have been uploaded with provenance metadata.

Select from 13 files

Attestation for contourrs-0.8.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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