hydromt.model.components.GridComponent.add_data_from_geodataframe#
- GridComponent.add_data_from_geodataframe(vector_data: str | Path | GeoDataFrame, variables: str | List[str] | None = None, nodata: List[int | float] | int | float | None = -1, rasterize_method: str | None = 'value', mask_name: str | None = 'mask', rename: Dict[str, str] | None = None, all_touched: bool | None = True) List[str] | None [source]#
HYDROMT CORE METHOD: Add data variable(s) to grid component by rasterizing the data from
vector_data
.- 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_data are used.
If this is used, variables must be specified.
- Parameters:
vector_data (
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_data. 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_data 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_data. 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_data’: ‘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: