geo-registry

Zonal statistics

Summary statistics of raster cell values inside each zone polygon.

Pitfall. Zones smaller than a cell may get no cells at all unless all_touched is set.
Pitfall. Overlapping zones are handled differently by different engines; some rasterize them and lose the overlap.
About this operation
Also called Zonal Statistics as Table, zonal stats, summarize raster within polygons
Group raster/statistics
Checks crs.agreement, raster.nodata, raster.stats_sampled
Pitfalls 2 listed above
Columbus tool raster_op · zonal_stats
Notes Not stated
Status active
Broader Not stated
Narrower Not stated
Related Not stated

Parameters

Name Type Required Default Values Note
stats list no Not stated count, mean, min, max, sum, std Not stated
band integer no Not stated Not stated Not stated
all_touched boolean no Not stated Not stated Count every cell a zone touches, not only cells whose centre is inside.

Inputs and outputs

Direction Name Type Geometry Note
Input raster raster Not stated Not stated
Input zones vector polygon Not stated
Output output vector Not stated Not stated

In each engine

Engine Tool Parameters Differences
gdal gdal raster zonal-stats
  • stats → stat : count = count; mean = mean; min = min; max = max; sum = sum; std = stdev
  • band → band
  • all_touched → pixels : true = all-touched; false = default
  • raster → input
  • zones → zones
  • output → output
  • Also offers fractional cell coverage (pixels fractional) and weighted statistics.
grass v.rast.stats
  • stats → method : count = number; mean = average; min = minimum; max = maximum; sum = sum; std = stddev
  • raster → raster
  • zones → map
  • Writes the statistics as new columns in the zone map's own attribute table; there is no separate output.
Preset: {"column_prefix":"zonal"}
qgis native:zonalstatisticsfb
  • stats → STATISTICS : count = 0; sum = 1; mean = 2; std = 4; min = 5; max = 6
  • band → RASTER_BAND
  • raster → INPUT_RASTER
  • zones → INPUT
  • output → OUTPUT
  • Output columns are named with COLUMN_PREFIX (default "_"), e.g. _mean.
rasterstats rasterstats.gen_zonal_stats
  • stats → stats : count = count; mean = mean; min = min; max = max; sum = sum; std = std
  • band → band
  • all_touched → all_touched
  • raster → raster
  • zones → vectors
  • A generator of one dict per zone; rasterstats.zonal_stats takes the same arguments and returns a list.
terra terra::zonal
  • stats → fun : count = notNA; mean = mean; min = min; max = max; sum = sum; std = sd
  • all_touched → touches
  • raster → x
  • zones → z
  • Zones can be a raster of zone codes or polygons (SpatVector); results come back as a data frame.
  • std is computed by R's sd (sample standard deviation).
whiteboxtools ZonalStatistics
  • stats → stat : mean = mean; min = minimum; max = maximum; std = standard deviation; sum = total. not supported: count
  • raster → input
  • zones → features : A raster of zone ids, not polygons: rasterize the zones onto the input's grid first.
  • output → output
  • Zones are a raster, not polygons, and it computes one statistic per run.
xarray-spatial xrspatial.zonal_stats
  • stats → stats_funcs : count = count; mean = mean; min = min; max = max; sum = sum; std = std
  • raster → values
  • zones → zones
  • Zones are a raster of zone ids on the same grid as values (polygons need rasterizing first); returns a pandas DataFrame per zone id.