hydromt.workflows.grid.grid_from_geodataframe#

hydromt.workflows.grid.grid_from_geodataframe(grid_like: DataArray | Dataset, gdf: GeoDataFrame, variables: List | str | None = None, nodata: List | int | float | None = -1, rasterize_method: str | None = 'value', mask_name: str | None = 'mask', rename: Dict | str | None = None, all_touched: bool | None = True) Dataset[source]#

Prepare data variable(s) resampled to grid_like object by rasterizing the data from gdf.

Several type of rasterization are possible:
  • “fraction”: returns the fraction of the grid cell covered by the gdf shape.

  • “area”: Returns the area of the grid cell covered by the gdf shape.

  • “value”: the value from the variables columns of gdf are used.

    If this is used, variables must be specified.

Parameters:
  • grid_like (xr.DataArray, xr.Dataset) – Grid to copy metadata from.

  • gdf (gpd.GeoDataFrame) – geopandas object to rasterize.

  • variables (List, str, optional) – List of variables to add to grid from vector_fn. Required if rasterize_method is “value”, by default None.

  • nodata (List, int, float, optional) – No data value to use for rasterization, by default -1. If a list is provided, it should have the same length has variables.

  • rasterize_method (str, optional) – Method to rasterize the vector data. Either {“value”, “fraction”, “area”}. If “value”, the value from the variables columns in vector_fn are used directly in the raster. If “fraction”, the fraction of the grid cell covered by the vector file is returned. If “area”, the area of the grid cell covered by the vector file is returned.

  • mask_name (str, optional) – Name of mask in self.grid to use for masking raster_fn. By default ‘mask’. Use None to disable masking.

  • rename (dict or str, optional) – Dictionary to rename variable names in variables before adding to grid {‘name_in_variables’: ‘name_in_grid’}. To rename with method fraction or area give directly ‘name_in_grid’ string. By default empty.

  • all_touched (bool, optional) – If True (default), all pixels touched by geometries will be burned in. If false, only pixels whose center is within the polygon or that are selected by Bresenham’s line algorithm will be burned in.

Returns:

ds_out – Dataset with data from vector_fn resampled to grid_like.

Return type:

xr.Dataset