skillfed

rasterstats

Summarize geospatial raster datasets based on vector geometries

rasterstats v0.21.0 439.4K downloads/30d#6,655 on PyPI561
Permissive license BSD-3-Clause Active released

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 rasterstats

uv

uv add rasterstats

poetry

poetry add rasterstats

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Scientific/Engineering :: GISTopic :: Utilities

Tags

zonal statistics raster vectorraster summarization by geometryextract raster values polygonspoint query raster datageospatial raster analysisdem statistics polygonraster zonal summary
geospatialraster-vectorgis

More Utilities packages