hydromt.GridModel.setup_grid_from_geodataframe#

GridModel.setup_grid_from_geodataframe(vector_fn: str | Path | GeoDataFrame, variables: List | str | None = None, nodata: List | int | float | None = -1, rasterize_method: str | None = 'value', mask_name: str | None = 'mask', rename: Dict | None = None, all_touched: bool | None = True) List[str]#

HYDROMT CORE METHOD: Add data variable(s) to grid object by rasterizing the data from vector_fn.

Several type of rasterization are possible:
  • “fraction”: the fraction of the grid cell covered by the vector

    shape is returned.

  • “area”: the area of the grid cell covered by the vector shape is returned.

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

    If this is used, variables must be specified.

Parameters:
  • vector_fn (str, Path, gpd.GeoDataFrame) – Data catalog key, path to vector file or a vector geopandas object.

  • 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, 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 use {‘vector_fn’: ‘name_in_grid’}. 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:

Names of added model grid layers

Return type:

list