raster_tools.general.regions#

raster_tools.general.regions(raster, neighbors=4, unique_values=None)[source]#

Calculates the unique regions (patches) within a raster band.

The approach is based on ESRI’s region group calculation.

Parameters
  • raster (Raster or path str) – The raster to perform the calculation on. All unique non zero values will be used to define unique regions.

  • neighbors (int, optional) – The neighborhood connectivity value. Valid values are 4 and 8. If 4, a rook pattern is used, e.g. the neighbors along the horizontal and vertical directions are used. if 8, then all of the 8 neighbors are used. Default is 4.

  • unique_values (array or list, optional) – Values that represent zones from which regions will be made. Values not included will be grouped together to form one large zone. If None, each unique value in the raster will be considered a zone and will be calculated up front.

Returns

The resulting raster of unique regions values. The bands will have the same shape as the original Raster. The null value mask from the origial raster will be applied to the result.

Return type

Raster

References