hydromt.gis.DataArray.raster.zonal_stats#

gis.DataArray.raster.zonal_stats(gdf: GeoDataFrame, stats: str | list[str] | Callable, variables: list[str] | None = None, all_touched: bool = False)#

Calculate zonal statistics of raster samples aggregated for geometries.

Parameters:
  • gdf (geopandas.GeoDataFrame) – GeoDataFrame with geometries

  • stats (str | list[str] | Callable) – Statistics to compute from raster values, options include {‘count’, ‘min’, ‘max’, ‘sum’, ‘mean’, ‘std’, ‘median’, ‘q##’}. Multiple percentiles can be calculated using comma-separated values, e.g.: ‘q10,50,90’. Statistics ignore the nodata value and are applied along the x and y dimension.

  • variables (list of str, optional) – List of variable names to calculate zonal statistics for. If None, all variables are used. By default None

  • all_touched (bool, optional) – If True, all pixels touched by geometries will used to define the sample. If False, only pixels whose center is within the geometry or that are selected by Bresenham’s line algorithm will be used. By default False.

Returns:

ojb_out – Output dataset with a variable for each combination of input variable and statistic.

Return type:

xr.Dataset