hydromt.gis.DataArray.raster.sample_geoms#

gis.DataArray.raster.sample_geoms(gdf: GeoDataFrame, sampling_strategy: Literal['centroid', 'representative_point'], stats: str | list[str] | Callable = 'mean', variables: list[str] | None = None)#

For each geometry, compute one sample point in the raster and compute stats across bands.

Fast sampling of raster values at geometry centroids (or representative points). Intended for cases where raster resolution >> geometry size. No rasterization or spatial aggregation is performed.

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

  • sampling_strategy ({'centroid', 'representative_point'}, optional) – Method to get point location from geometry. ‘centroid’: use geometry centroid ‘representative_point’: use geometry representative point. By default ‘representative_point’

  • stats (str, list of str, callable, optional) – Statistics to compute from raster values, options include {‘mean’, ‘min’, ‘max’, ‘sum’, ‘std’, ‘median’}. Multiple statistics can be calculated by providing a list. Only applicable when raster has multiple bands (e.g. time series). If the raster has a single band, the sampled value is returned directly, ignoring stats. By default None

  • variables (list of str, optional) – List of variable names to sample from dataset. If None, all variables are sampled. By default None

Returns:

obj_out – Output dataset with a variable for each combination of input variable and statistic. Note that the output dataset can have nodata values if sampled points fall outside the raster extent. Handling this is the responsibility of the caller.

Return type:

xr.Dataset