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 label diagonal neighbors as one region. Parts that touch only at corners are still exported as separate polygons; see the connectivity semantics. 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.6

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.6
File Size Uploaded Provenance Actions
contourrs-0.8.6.tar.gz 51.8 kB With provenance Details for contourrs-0.8.6.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for contourrs 0.8.6
File Actions
contourrs-0.8.6-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for contourrs-0.8.6-cp314-cp314-win_amd64.whl
contourrs-0.8.6-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.6-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
contourrs-0.8.6-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.6-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
contourrs-0.8.6-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for contourrs-0.8.6-cp314-cp314-macosx_11_0_arm64.whl
contourrs-0.8.6-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for contourrs-0.8.6-cp313-cp313-win_amd64.whl
contourrs-0.8.6-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.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
contourrs-0.8.6-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.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
contourrs-0.8.6-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for contourrs-0.8.6-cp313-cp313-macosx_11_0_arm64.whl
contourrs-0.8.6-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for contourrs-0.8.6-cp312-cp312-win_amd64.whl
contourrs-0.8.6-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.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
contourrs-0.8.6-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.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
contourrs-0.8.6-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for contourrs-0.8.6-cp312-cp312-macosx_11_0_arm64.whl

Total release size: 9.6 MB

Release files / contourrs-0.8.6.tar.gz

Download URL contourrs-0.8.6.tar.gz
Size 51.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e08afb922d1f2251f76daabc12424873f04167696dfcf472336c856c5da9d73c
BLAKE2b-256 checksum
How to use checksums
4ead4c8aa5bff1c95c2c85eafb47d3810e58aaca784ef017aff8a04eb67d0ef7
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp314-cp314-win_amd64.whl
Size 597.3 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
93dbe08af7692ba9b5235e74ea8818c4c26bd97638089173cbb15188d01bf130
BLAKE2b-256 checksum
How to use checksums
0f604159b961539d353991153debb6b0f24961f1b4e6ae3fdb37eefabcca9635
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d4156ee6b4ab62aef42e5658f73954decaf21bc3dd5f7415c2cb8b4a23247bf0
BLAKE2b-256 checksum
How to use checksums
c159d741aa511cd9cd6798f88830055236ae9c0058b18a63886590f7637b06d3
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 802.5 kB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
97d34f22c5156d25112f9d5e5a0f6e0c4a92a6d055c93b747b544334dba4bbd6
BLAKE2b-256 checksum
How to use checksums
b66436ea36b56c5439db7f8328135dd9304d59d845dfa916dfe7e5c44069e4d2
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp314-cp314-macosx_11_0_arm64.whl
Size 715.7 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b588a48adb9200065cd3a50239de78e10a874c9013a6f7601b3f44353ae55d33
BLAKE2b-256 checksum
How to use checksums
997afb9864fcc3fae03476018c872deb64d0014efaa25b2cbdb5f819982bb0c4
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp313-cp313-win_amd64.whl
Size 600.6 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
66effba451833388cf31b429578629957770219eee880e1a7318849966b9809a
BLAKE2b-256 checksum
How to use checksums
4266936dc930ddafe34d778d1958e32df2112a2eee57f36049b4d32140a51e47
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1081f87e0ff10f33d83b9e1e487c8a21beb8f619f8bc762084a2757628c84677
BLAKE2b-256 checksum
How to use checksums
92304bd85afce44c7da10dbf077008d8530649b5b80bd0b7a9eb4af77f24036f
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 801.9 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
bb4b9a23b55845bb7f32a9306216bb7e3cf6d67581c129bea27f2b1c61d5ce6a
BLAKE2b-256 checksum
How to use checksums
ad677b88a945c55e63a6bf7504b7248b2174a5d08700098c2811bd4a1ade17bb
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp313-cp313-macosx_11_0_arm64.whl
Size 711.6 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8490d1d0a44d24b16442589bdaa3fcd8c85a34fa321bbe8247f61e80e7f7fd48
BLAKE2b-256 checksum
How to use checksums
2f9a203b5ef03f7e91c0b536b7d95fe7138263c6f14f31b4e19ffa16fd1aaf53
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp312-cp312-win_amd64.whl
Size 600.8 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
f3ea9752b9b9fac2b5d26dd355a40bfade36517460a5d763f1116e8014388078
BLAKE2b-256 checksum
How to use checksums
530b38d031ce09ece81b5d3c9e2c86111bee5a91af013b668c1efe0e5058e3c5
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5ae740cdcacde682840c0323c81a234cbd0f037cffd717459d2dc476287afbe4
BLAKE2b-256 checksum
How to use checksums
d16fc997966f8ace6003ac02a55afb24409b74477284281a840803c7253087b5
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 801.8 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
7cc2e5f4bb3bd0ba01e7a44e43604ea34cd69332e307fb76ad95623b99e8e52e
BLAKE2b-256 checksum
How to use checksums
00f1f6e0eafaf1bb57fa7039c7521a48057841f11284c3cdd77a80ba9334cf6c
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 27, 2026.

Transparency log

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

Download URL contourrs-0.8.6-cp312-cp312-macosx_11_0_arm64.whl
Size 711.4 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5cbf48edd9daa331d8508cca1296ad2bca747beb21190be7329a2cd4b4d7b2bc
BLAKE2b-256 checksum
How to use checksums
1d98c663ce402ae0207fc0836af7a6b2adf120f2d900bf452d704de79d1fc130
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 27, 2026.

Transparency log

Security for contourrs 0.8.6

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.6.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 27, 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