raptor-stats

Docs: latest PyPI Python  3.12.8+ License

Compute zonal statistics using efficient Raptor (Raster+Vector) methods.

Installation

pip install raptor-stats

Usage

from raptorstats import zonal_stats

stats = zonal_stats("path/to/vector.shp", "path/to/raster.tif", method="scanline")

See the zonal_stats API docs for more details on input types and additional parameters.

Methods

  • scanline: Scans the raster file once, line by line, and computes all the intersections with the vector layer in a single pass. Suitable for fast one-time run results.

  • agqt: Builds a QuadTree with precomputed statistics, then combines it with the scanline method to answer queries more efficiently. Suitable for systems that repeatedly query changing vector layers over the same raster.

Performance

Raptor methods performance advantage increases with the size of the input raster and number of features. For example, with an ~1.9 billion pixel raster and 50 features (US states):

See images at https://github.com/simonpedrogonzalez/raptor-stats/blob/main/README.md

For the same raster, on but around 3000 features (US counties):

See images at https://github.com/simonpedrogonzalez/raptor-stats/blob/main/README.md

NOTES:

  • These tests were made on a i7-8750H (2019) 16GB RAM Linux machine.

  • The performance of the agqt method depends on the depth of the tree selected and the size of the features.

Credits