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

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.4
File Size Uploaded Provenance Actions
contourrs-0.8.4.tar.gz 51.4 kB With provenance Details for contourrs-0.8.4.tar.gz

Built distributions (wheels)

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

Total release size: 9.6 MB

Release files / contourrs-0.8.4.tar.gz

Download URL contourrs-0.8.4.tar.gz
Size 51.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d848bfd30ad4e689b8d8cd0e6dbcaf4643bdd66dd1e0d4ebf77d92733c120a81
BLAKE2b-256 checksum
How to use checksums
803f0a8c87648e4be0b8309e62c30fbd6e134b2871140085196af7ea8a90f29a
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.4-cp314-cp314-win_amd64.whl

Download URL contourrs-0.8.4-cp314-cp314-win_amd64.whl
Size 594.7 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
9523c68120f2ecbe1683482ab5e98b7344053bc8368d268780c7cf0f4fe5201d
BLAKE2b-256 checksum
How to use checksums
0e31f0bcea459a2e79b7f40748c0ca1b22f63674706abe7f5ef46ea9419d4923
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.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL contourrs-0.8.4-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
26de2bbf737bc22c9de4658e198ce55ace95a8a952452eaf0b93a0b00cae77ad
BLAKE2b-256 checksum
How to use checksums
661f96e7462d745035e45de33972684190e19a7fe7fe0067e1e65f843b223ad8
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.4-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL contourrs-0.8.4-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 799.1 kB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
16312205e35ef44fcfd2d6c1452ae25ed2e2215290743e94d0d4d9c0c00c8c4c
BLAKE2b-256 checksum
How to use checksums
bd5272cf5c89836d6d3abb40d2ecdc8e88bc35e45c7952656072872a6614128a
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.4-cp314-cp314-macosx_11_0_arm64.whl

Download URL contourrs-0.8.4-cp314-cp314-macosx_11_0_arm64.whl
Size 711.6 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
776e134698f29ba8759f6aee69e9133d0d04e3b0ca5e7f1d651a8db9728e5fde
BLAKE2b-256 checksum
How to use checksums
d349b3b35e0b2ab62ce00f67842cd394d4d80ae1d680b4f8f1bd974dd6cdf2c8
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.4-cp313-cp313-win_amd64.whl

Download URL contourrs-0.8.4-cp313-cp313-win_amd64.whl
Size 597.3 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
287e3bb56230525657ddf8e3ed436098d5771b42977695fb6a61836fe8f96750
BLAKE2b-256 checksum
How to use checksums
39cd43f38725b31806d42fb593f5db1bd3f8f98908f7d9294318a5d5845239f6
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.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL contourrs-0.8.4-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
e5f058b98e3eda8a7c40145f31699eadd13767767d3b3244cc685f278379ca19
BLAKE2b-256 checksum
How to use checksums
121869e5e51ca2f4b43f8aa752b4e93a8f0e9257e6c484c692133d78696d1080
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.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL contourrs-0.8.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 798.1 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
2c8c6483a34091f754f4a2a133aee156ab58cc2fb252d298a3b0c48b39e2c7fe
BLAKE2b-256 checksum
How to use checksums
ed4a7557c183ee1fa16f8d9f0faf4eb8e777b5f7905b00169dc5336cfc903d91
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.4-cp313-cp313-macosx_11_0_arm64.whl

Download URL contourrs-0.8.4-cp313-cp313-macosx_11_0_arm64.whl
Size 708.0 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d1b4dfb5e50a5804a308ee4fd117fb2708c934ffc8ab54a23410837415edb347
BLAKE2b-256 checksum
How to use checksums
1b920448a7a04b2e40d53e09d35edc86f4517f7f2b423b31046566dd907938bb
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.4-cp312-cp312-win_amd64.whl

Download URL contourrs-0.8.4-cp312-cp312-win_amd64.whl
Size 597.4 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
91c68d60fadacee4b52967cbee14d3dd71df96e6ed7588060d5f72b331860321
BLAKE2b-256 checksum
How to use checksums
21728ac225549e2d2814ca1192f48641792d4ef20eff19eee90001d2002aa3f1
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.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL contourrs-0.8.4-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
73d5a47e01773eb3b8947b5656f0453b767b397adf4bdc5bdedca4d1fc9618df
BLAKE2b-256 checksum
How to use checksums
6a296ed2d6e19de8cbb326cf8114074d75ba03c32cfcf4414efb0de067512ae8
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.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL contourrs-0.8.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 798.4 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
3ca18a798fa3f161fe625bf10d05a4bd64f4393491ab9041ab5004161e3adba9
BLAKE2b-256 checksum
How to use checksums
075ffd392e585aa0ca1357c9567e227cab56044823927dca4cf34f9f6fe66495
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.4-cp312-cp312-macosx_11_0_arm64.whl

Download URL contourrs-0.8.4-cp312-cp312-macosx_11_0_arm64.whl
Size 708.1 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
67891f5cc5fbcbe226f03c160769da30232c256b01f74b231ea75914f186c572
BLAKE2b-256 checksum
How to use checksums
57de025f515927dddb2fdf74806d9860918bfb5281c7bef5ba2bf03cc1c9b543
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.4

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