pyflwdir.regions.region_dissolve#

pyflwdir.regions.region_dissolve(regions: ndarray, labels: ndarray | None = None, idxs: ndarray | None = None, transform: Affine = Affine(1.0, 0.0, 0.0, 0.0, -1.0, 0.0), latlon: bool = False, **kwargs) → ndarray[source]#

Dissolve selected regions into their nearest neighboring regions.

Select regions by their labels or by one linear-index location per region in idxs. Each selected region is assigned the ID of its nearest neighboring region. When idxs is provided, proximity is measured from those locations, which can be useful for dissolving basins based on the distance from their outlets.

Parameters:
  • regions (2D array of int) – Raster of positive region IDs, with zero reserved for background.

  • labels (1D array of int, optional) – Unique positive IDs of regions to dissolve. Provide either labels or idxs.

  • idxs (1D array of int, optional) – One linear-index location per region to dissolve. Provide either idxs or labels.

  • transform (Affine, optional) – Affine transform from pixel coordinates to the coordinate reference system.

  • latlon (bool, optional) – True for geographic CRS, False for projected CRS. If True, transform units are interpreted as degrees and distances are converted to metres, by default False.

  • **kwargs (dict) – Additional keyword arguments passed to gis_utils.spread2d.

Returns:

basins_out – Raster with the selected regions dissolved into neighboring region IDs.

Return type:

2D-array of int