xrspatial.slope.slope

xrspatial.slope.slope(agg: xarray.core.dataarray.DataArray, name: str = 'slope')xarray.core.dataarray.DataArray[source]

Returns slope of input aggregate in degrees.

agg: xarray.DataArray

2D array of elevation band data.

name: str, optional (default = ‘slope’)

name property of output xarray.DataArray

xarray.DataArray

2D array, of the same type as the input, of calculated slope values. All other input attributes are preserved.

Algorithm References: - esri, How Slope works, http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-slope-works.htm, Accessed Apr. 22, 2021. # noqa - Burrough, P. A., McDonnell, R., McDonnell, R. A., & Lloyd, C. D. (1998). Principles of geographical information systems. Oxford university press. pp 406. # noqa

Imports >>> import numpy as np >>> import xarray as xr >>> from xrspatial import slope

Create Data Array >>> agg = xr.DataArray(np.array([[0, 0, 0, 0, 0, 0, 0], >>> [0, 0, 2, 4, 0, 8, 0], >>> [0, 2, 2, 4, 6, 8, 0], >>> [0, 4, 4, 4, 6, 8, 0], >>> [0, 6, 6, 6, 6, 8, 0], >>> [0, 8, 8, 8, 8, 8, 0], >>> [0, 0, 0, 0, 0, 0, 0]]), >>> dims = [“lat”, “lon”], >>> attrs = dict(res = 1)) >>> height, width = agg.shape >>> _lon = np.linspace(0, width - 1, width) >>> _lat = np.linspace(0, height - 1, height) >>> agg[“lon”] = _lon >>> agg[“lat”] = _lat

Create Slope Data Array >>> print(slope(agg)) <xarray.DataArray ‘slope’ (lat: 7, lon: 7)> array([[ 0, 0, 0, 0, 0, 0, 0],

[ 0, 46, 60, 63, 73, 70, 0], [ 0, 60, 54, 54, 68, 67, 0], [ 0, 68, 60, 54, 60, 71, 0], [ 0, 73, 63, 60, 54, 72, 0], [ 0, 74, 71, 71, 72, 75, 0], [ 0, 0, 0, 0, 0, 0, 0]])

Coordinates:
  • lon (lon) float64 0.0 1.0 2.0 3.0 4.0 5.0 6.0

  • lat (lat) float64 0.0 1.0 2.0 3.0 4.0 5.0 6.0

xrspatial.slope.res

1