hydromt_wflow.components.WflowGeomsComponent#

Summary of Methods and Attributes#

class WflowGeomsComponent(model: Model, *, filename: str = 'staticgeoms/{name}.geojson', region_component: str | None = None, region_filename: str = 'staticgeoms/geoms_region.geojson')[source]#

Bases: GeomsComponent

Wflow Geoms Component to manage spatial geometries.

It extends the base GeomsComponent from hydromt and consists of a dictionary of geopandas GeoDataFrames.

read(folder: str = 'staticgeoms')[source]#

Read static geometries and adds to geoms.

If dir_input is set in the config, the path where all static geometries are read, will be constructed as <model_root>/<dir_input>/<geoms_fn>. Where <dir_input> is relative to the model root. Depending on the config value dir_input, the path will be constructed differently.

Parameters:

folder (str, optional) – Folder name/path where the static geometries are stored relative to the model root and dir_input if any. By default “staticgeoms”.

write(folder: str = 'staticgeoms', to_wgs84: bool = False, precision: int | None = None, **kwargs) None[source]#

Write model geometries to vector file(s) (by default GeoJSON) at <dir_out>/*.geojson.

Checks the path of geoms_fn using both model root and dir_input. If not found uses the default path staticgeoms in the root folder.

Key-word arguments are passed to geopandas.GeoDataFrame.to_file()

Parameters:
  • folder (Path, optional) – The directory to write the geometry files to. If it does not exist, it will be created.

  • to_wgs84 (bool, optional) – If True, the geoms will be reprojected to WGS84(EPSG:4326) before being written.

  • precision (int, optional) – The precision to use for writing the geometries. If None, it will be set to 1 for projected CRS and 6 for geographic CRS.

  • **kwargs (dict) – Additional keyword arguments that are passed to the geopandas.to_file function.

get(name: str) GeoDataFrame | GeoSeries[source]#

Get geometry by name.

Parameters:

name (str) – The name of the geometry to retrieve.

Returns:

The geometry associated with the given name.

Return type:

gpd.GeoDataFrame | gpd.GeoSeries

Raises:

KeyError – If the geometry with the specified name does not exist.

pop(name: str) GeoDataFrame | GeoSeries[source]#

Remove and return geometry by name.

Parameters:

name (str) – The name of the geometry to remove and return.

Returns:

The geometry associated with the given name.

Return type:

gpd.GeoDataFrame | gpd.GeoSeries

Raises:

KeyError – If the geometry with the specified name does not exist.

clear() None[source]#

Clear all geometries.

test_equal(other: ModelComponent) tuple[bool, dict[str, str]][source]#

Test if two GeomsComponents are equal.

Parameters:

other (GeomsComponent) – The other GeomsComponent to compare with.

Returns:

True if the components are equal, and a dict with the associated errors per property checked.

Return type:

tuple[bool, dict[str, str]]

property bounds: Tuple[float, float, float, float] | None#

Return the total bounds of the model region.

close() None#

Clean up all open datasets. Method to be called before finish_write.

property crs: CRS | None#

Provide access to the CRS of the model region.

property data: Dict[str, GeoDataFrame | GeoSeries]#

Model geometries.

Return dict of geopandas.GeoDataFrame or geopandas.GeoSeries

property data_catalog: DataCatalog#

Return the data catalog of the model this component is associated with.

finish_write()#

Finish the write functionality after cleanup was called for all components in the model.

All DeferredFileClose objects can overwrite any lazy loaded files now.

property model: Model#

Return the model object this component is associated with.

property name_in_model: str#

Find the name of the component in the parent model components.

property region: GeoDataFrame | None#

Provide access to the underlying GeoDataFrame data of the model region.

property root: ModelRoot#

Return the root of the model this component is associated with.

set(geom: GeoDataFrame | GeoSeries, name: str)#

Add data to the geom component.

Parameters:
write_region(filename: str | None = None, *, to_wgs84: bool = False, to_file_kwargs: dict[str, Any] | None = None) None#

Write the model region to file.

The region is an auxiliary file that is often not required by the model, but can be useful for getting data from the data catalog. Plugin implementors may choose to write this file on write for a specific component.

Parameters:
  • filename (str, optional) – The filename to write the region to. If None, the filename provided at initialization is used.

  • to_wgs84 (bool) – If True, the region is reprojected to WGS84 before writing.

  • to_file_kwargs (dict, optional) – Additional keyword arguments passed to the geopandas.GeoDataFrame.to_file function.