rasterstats
Summarize geospatial raster datasets based on vector geometries
What it is and what it does
Rasterstats is a geospatial analysis library that bridges raster and vector data by computing statistics from raster datasets within vector geometry boundaries. Given a vector layer (polygons, lines, or points) and a raster band (such as a digital elevation model), it calculates aggregate statistics like mean, min, max, and count for each geometry. It also supports point queries to extract raster values at specific coordinates. The package wraps rasterio for raster I/O and shapely for geometry handling, and provides both a Python API and command-line interfaces (via rio subcommands) for integration with GeoJSON workflows.
The library is designed for GIS workflows where you need to summarize continuous raster data (elevation, temperature, precipitation, satellite imagery) by administrative or analytical boundaries. It handles the geometric intersection and pixel aggregation internally, making it straightforward to compute landscape statistics for polygons or sample raster values at point locations without writing custom spatial indexing code.
Use it for:
- Calculate mean elevation or slope within each administrative boundary (county, watershed, grid cell) from a DEM.
- Extract average temperature or precipitation values for polygon regions from climate raster datasets.
- Query satellite imagery or land-use raster values at survey point locations for classification or validation.
- Summarize vegetation indices (NDVI) or other derived rasters across field polygons for agricultural analysis.
- Batch compute zonal statistics from the command line by piping GeoJSON features through rio subcommands.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Rasterstats computes summary statistics (mean, min, max, count) from raster datasets for vector geometries, and queries raster values at point locations.
Yes. Rasterstats is actively maintained, has no known vulnerabilities, low install friction, and solves a common GIS task (zonal statistics) that would otherwise require custom spatial code. It is well-suited for anyone working with raster and vector data in Python, from climate and environmental analysis to remote sensing. The permissive BSD license poses no restriction.
Install
rasterstats on PyPI
pip
pip install rasterstatsuv
uv add rasterstatspoetry
poetry add rasterstatsInstalling rasterstats
Before you install
Low friction: pure Python wheel with no compiled dependencies beyond rasterio and its transitive stack. Actively maintained with a recent release (83 days old) and steady commit history.
License in practice
BSD-3-Clause is permissive; you may use, modify, and distribute rasterstats freely in commercial and proprietary projects provided you include the license text and disclaim liability.
Quickstart
pip install rasterstats
from rasterstats import zonal_stats
stats = zonal_stats("polygons.shp", "elevation.tif")
print(stats[0]['mean'])
Requires rasterio and its system dependencies (GDAL/GEOS libraries); vector and raster files must be accessible on disk or via a path.
Verify before relying
- Performance characteristics with large raster datasets or many geometries are not documented in the fact sheet.
- Whether the package supports cloud-optimized GeoTIFF or remote raster sources via rasterio's capabilities is unclear from the description.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 8 — affine, click, cligj, numpy, pyogrio, rasterio, shapely, simplejson |
| Maintenance | actively maintained — 83 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 439,438/month — #6,655 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: rasterstats-0.21.0-py3-none-any.whl
Keywords: geographic, geospatial, gis, raster, vector, zonal statistics
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
exactextractexactextract computes zonal statistics—fast…
permissive · top 15,000 on PyPI
runstatsComputes summary statistics (mean, variance,…
permissive · top 15,000 on PyPI
rasterioRasterio reads and writes geospatial raster…
permissive · top 5,000 on PyPI
statisticsProvides basic mathematical statistics…
permissive · top 15,000 on PyPI
xarray-spatialxarray-spatial provides 150+ functions for…
permissive · top 15,000 on PyPI
leafmapLeafmap enables interactive geospatial mapping…
permissive · top 15,000 on PyPI
stats-canFetches Statistics Canada data through the Web…
copyleft · top 15,000 on PyPI
facets-overviewGenerates summary statistics for dataset…
permissive · top 15,000 on PyPI
arcgisAccess Esri's ArcGIS services and geospatial…
unclear · top 15,000 on PyPI
scikit-miscscikit-misc provides miscellaneous tools for…
permissive · top 15,000 on PyPI