geodata.mask.filter_raster

geodata.mask.filter_raster#

geodata.mask.filter_raster(raster: rasterio.DatasetReader, values: Iterable[float] | None = None, min_bound: float | None = None, max_bound: float | None = None, binarize: bool = False) rasterio.DatasetReader#

Filter the raster with a list of values to be True. This method can also set a min bound and max bound to select values in the raster higher or lower than these two boundaries. If binarize is False (by default), the method will return the original values of the raster that satisfy the condition.

Parameters:
  • raster (ras.DatasetReader) – The source raster

  • values (list) – The list of numberic values in the raster array to filter out as 1. Optional. If not specified, the method will not filter out any values in the raster.

  • min_bound (float) – The minimum value in the raster array to filter out as 1. Optional. If not specified, the method will not filter out any values lower than the min_bound.

  • max_bound (float) – The maximum value in the raster array to filter out as 1 Optional. If not specified, the method will not filter out any values higher than the max_bound.

  • binarize (bool) – Whether the method will return 0 and 1 for the raster

Returns:

The filtered raster.

Return type:

ras.DatasetReader

Raises:

ValueError – If no values, min_bound, nor max_bound are specified.