xrspatial.zonal.apply

xrspatial.zonal.apply(zones: xarray.core.dataarray.DataArray, values: xarray.core.dataarray.DataArray, func: Callable)[source]

Apply a function to the values agg within zones in zones agg. Change the agg content.

zones: xarray.DataArray,
  • zones.values is a 2d array of integers.

  • A zone is all the cells in a raster that have the same value, whether or not they are contiguous. The input zone layer defines the shape, values, and locations of the zones. An integer field in the zone input is specified to define the zones.

agg: xarray.DataArray,
  • agg.values is either a 2D or 3D array of integers or floats.

  • The input value raster.

func: callable function to apply.

None

>>> zones_val = np.array([[1, 1, 0, 2],
>>>                       [0, 2, 1, 2]])
>>> zones = xarray.DataArray(zones_val)
>>> values_val = np.array([[2, -1, 5, 3],
>>>                   [3, np.nan, 20, 10]])
>>> agg = xarray.DataArray(values_val)
>>> func = lambda x: 0
>>> apply(zones, agg, func)
>>> agg
>>> array([[0, 0, 5, 0],
>>>        [3, 0, 0, 0]])