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.5

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.5
File Size Uploaded Provenance Actions
contourrs-0.8.5.tar.gz 51.6 kB With provenance Details for contourrs-0.8.5.tar.gz

Built distributions (wheels)

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

Total release size: 9.6 MB

Release files / contourrs-0.8.5.tar.gz

Download URL contourrs-0.8.5.tar.gz
Size 51.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7be9a3c924624efd01ac55563e648331da9dd76271e75be3b886b849b9e1532b
BLAKE2b-256 checksum
How to use checksums
701f68a0ce2042521f9ecf321cedebaa084daa09efe9ef55de67bf7185e792a7
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.5-cp314-cp314-win_amd64.whl

Download URL contourrs-0.8.5-cp314-cp314-win_amd64.whl
Size 595.4 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
f76107bd6df96eaca27475593d00f28fe84693ee934ac2989bc4dd09983b6a17
BLAKE2b-256 checksum
How to use checksums
16938816c0bb3ece7bdd99732ac80b256601d27bed4725ce2966a6e095874da9
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.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL contourrs-0.8.5-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
e3e9886eb734f773c2e24d3d818f7defb7a53d52c0260225a88bd95fa2918cb2
BLAKE2b-256 checksum
How to use checksums
966de232d86acb4c495b9a177ce4d3aa4ced8666665cbb7fefedc8b20b4256a5
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.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL contourrs-0.8.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 800.1 kB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
cb67478cebd28e700425dc9ba30fcd8617d739a39dd2da5218936e39a457ebea
BLAKE2b-256 checksum
How to use checksums
8c2b0dca825b25d6987714fc888eda8ab8cd3dff4d0ecef05d785ea5e59fe95b
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.5-cp314-cp314-macosx_11_0_arm64.whl

Download URL contourrs-0.8.5-cp314-cp314-macosx_11_0_arm64.whl
Size 712.6 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5c2183dae678d2f83761a6fe3ac94aaf774e9902421794a3713c53211d9a5049
BLAKE2b-256 checksum
How to use checksums
eff3174c0e37b6811bd522275dc0dc64a9b69efb47776c72b4bb83eda8f5cba2
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.5-cp313-cp313-win_amd64.whl

Download URL contourrs-0.8.5-cp313-cp313-win_amd64.whl
Size 598.2 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
9466bc8530b051696667555177d64963d4a17d512e7af062809b43569db000f7
BLAKE2b-256 checksum
How to use checksums
3d6191937f5799e3524510b97ec81d41c5d35fc8ac6b8c51af1a80175431eb5f
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.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL contourrs-0.8.5-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
7f6c314ffd78fdeb64f57e6b500eeaa4b01f93f569cd9ad11db0d7ab92ff7c7e
BLAKE2b-256 checksum
How to use checksums
3fd39e730aefd9e5f788b765757aabe922d5281fe2b5288e220d192813a07e15
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.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL contourrs-0.8.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 799.2 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
6f1ad275de7c275346384f57560273acba1d1a1c53bb08562aa9c87a5915daed
BLAKE2b-256 checksum
How to use checksums
109ddf888c489ace65b0f24236c8078ccdb1c457369192811b28fff520eede5d
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.5-cp313-cp313-macosx_11_0_arm64.whl

Download URL contourrs-0.8.5-cp313-cp313-macosx_11_0_arm64.whl
Size 709.1 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b4be59f08e2912b46a32d76b719892425424962fa1e5c82e9ec914a8b51773aa
BLAKE2b-256 checksum
How to use checksums
b6f17bb63041337fe2d8ac112de085035d26ea113016f6cc1762e61a6894a5b0
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.5-cp312-cp312-win_amd64.whl

Download URL contourrs-0.8.5-cp312-cp312-win_amd64.whl
Size 598.2 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
75ea1b928e223c3491ef3bf8f185291f0f2f7ba63e694658315742bd6929f3cd
BLAKE2b-256 checksum
How to use checksums
bc04c1b680c7bb558b50695168a00ecab83ba317f2b6e41cf7d2b6dcc3776d64
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.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL contourrs-0.8.5-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
3eadc0959b4015a7b4aad24f678f1c495ca789783c293cf1ade2b2cf16c19b73
BLAKE2b-256 checksum
How to use checksums
e9ae88749e78b93631567a069c17984dc5d26d972c1b6982042494ddc39ab6d8
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.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL contourrs-0.8.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 799.2 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
9fb444c65c4454d44ae07b80bbba01e934d5cbbd4c7872a02cba2ad52f87c422
BLAKE2b-256 checksum
How to use checksums
f85969e7194366c62e0ab093f6cb5888f27df21302d02bd41eeb26b0e3b23274
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.5-cp312-cp312-macosx_11_0_arm64.whl

Download URL contourrs-0.8.5-cp312-cp312-macosx_11_0_arm64.whl
Size 708.9 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
985d7ecf601ab2cf50902eb2ec22a434f26255895cb1910635d8eede8cb3c845
BLAKE2b-256 checksum
How to use checksums
6a1e31c9f85a9ef9b1e2a1a10461c702cb556942033b33fbb81b688fcf3b748f
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.5

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.5.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