Skip to content

Summary statistics of geospatial raster datasets based on vector geometries.

License

Notifications You must be signed in to change notification settings

perrygeo/python-rasterstats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6a2769a · Sep 27, 2024
Sep 27, 2024
Feb 28, 2023
Feb 28, 2023
Oct 5, 2022
Sep 27, 2024
Jun 28, 2023
Feb 16, 2023
Mar 21, 2017
Sep 27, 2024
Sep 19, 2013
Feb 5, 2023
Jan 31, 2021
Sep 19, 2024
Feb 5, 2023
Feb 5, 2023

Repository files navigation

rasterstats

BuildStatus

rasterstats is a Python module for summarizing geospatial raster datasets based on vector geometries. It includes functions for zonal statistics and interpolated point queries. The command-line interface allows for easy interoperability with other GeoJSON tools.

Documentation

For details on installation and usage, visit the documentation at http://pythonhosted.org/rasterstats.

What does it do?

Given a vector layer and a raster band, calculate the summary statistics of each vector geometry. For example, with a polygon vector layer and a digital elevation model (DEM) raster, compute the mean elevation of each polygon.

zones elevation

Command Line Quick Start

The command line interfaces to zonalstats and point_query are rio subcommands which read and write geojson features

$ fio cat polygon.shp | rio zonalstats -r elevation.tif

$ fio cat points.shp | rio pointquery -r elevation.tif

See the CLI Docs. for more detail.

Python Quick Start

For zonal statistics

>>> from rasterstats import zonal_stats
>>> stats = zonal_stats("tests/data/polygons.shp", "tests/data/slope.tif")
>>> stats[0].keys()
dict_keys(['min', 'max', 'mean', 'count'])
>>> [f['mean'] for f in stats]
[14.660084635416666, 56.60576171875]

and for point queries

>>> from rasterstats import point_query
>>> point = {'type': 'Point', 'coordinates': (245309.0, 1000064.0)}
>>> point_query(point, "tests/data/slope.tif")
[74.09817594635244]

Issues

Find a bug? Report it via github issues by providing

  • a link to download the smallest possible raster and vector dataset necessary to reproduce the error
  • python code or command to reproduce the error
  • information on your environment: versions of python, gdal and numpy and system memory