raster_tools.general.where#

raster_tools.general.where(condition, true_rast, false_rast)[source]#

Return elements chosen from true_rast or false_rast depending on condition.

The mask for the result is a combination of all three raster inputs. Any cells that are masked in the condition raster will be masked in the output. The rest of the cells are masked based on which raster they were taken from, as determined by the condition raster, and if the cell in that raster was null. Effectively, the resulting mask is determined as follows: where(condition.mask, True, where(condition, true_rast.mask, false_rast.mask).

true_rast and false_rast can both be None to indicate a null value but they cannot both be None at the same time. An error is raised in that case.

Parameters
  • condition (str or Raster) – A boolean or int raster that indicates where elements in the result should be selected from. If the condition is an int raster, it is coerced to bool using condition > 0. True cells pull values from true_rast and False cells pull from y. str is treated as a path to a raster.

  • true_rast (scalar, Raster, str, None) – Raster or scalar to pull from if the corresponding location in condition is True. If None, this is treated as a null value.

  • false_rast (scalar, Raster, str, None) – Raster or scalar to pull from if the corresponding location in condition is False. If None, this is treated as a null value.

Returns

The resulting Raster.

Return type

Raster