imod.prepare.zonal_aggregate_raster(path: Union[pathlib.Path, str], column: str, raster: xarray.core.dataarray.DataArray, resolution: float, method: Union[str, Callable], chunksize: int = 10000.0) pandas.core.frame.DataFrame[source]#

Compute a zonal aggregate of raster data for polygon geometries, e.g. a mean, mode, or percentile.

  • path (str or pathlib.Path) – path to OGR supported vector file (e.g. a shapefile). Defines zones of aggregation.

  • column (str) – column name of path, integer IDs defining zones.

  • resolution (float) – cellsize at which the rasterization of polygons and sampling occurs

  • raster (xarray.DataArray) – Raster data from which to sample and aggregate data

  • method (Union[str, Callable]) – Aggregation method. Anything that is acceptable by a pandas groupby aggregate:

  • chunksize (int, optional) – The size of the chunksize. Used for both x and y dimension.



Return type



To compute the mean surface level at polygons of water bodies:

>>> import imod
>>> surface_level ="surface_level.tif")
>>> df = imod.prepare.spatial.overlay_raster_intersection(
>>>    "water-bodies.shp", "id", 1.0, surface_level, "mean"
>>> )

For some functions, like the mode, a function should be passed instead:

>>> import pandas as pd
>>> df = imod.prepare.spatial.overlay_raster_intersection(
>>>    "water-bodies.shp", "id", 1.0, surface_level, pd.Series.mode
>>> )