Aspect identifies the compass direction of the maximum rate of change in value from each cell to its neighbors. Aspect can be thought of as the slope direction.
Consider a 3x3 moving window over a raster, with 'a' to 'i' representing cell values. This moving 3x3 window visits each cell in the input raster and an aspect value is calculated for the cell in the center of the window, using an algorithm that incorporates the values of the cell’s eight neighbors.
If any neighborhood cells are NoData, they are assigned the value of the center cell. An example of this is when the 3x3 window is on an edge of a raster.
Taking the illustration above, the rate of change in the x direction for cell ‘e’ is calculated with the following algorithm:
(dz/dx) = ((c + 2f + i) - (a + 2d + g)) / 8
(dz/dx) = ((85 + 170 + 84)) - (101 + 202 + 101)) / 8
(dz/dx) = -8.125
The rate of change in the y direction for cell ‘e’ is calculated with the following algorithm:
(dz/dy) = ((g + 2h + i) - (a + 2b + c)) / 8
(dz/dy) = ((101 + 182 + 84) - (101 + 184 + 85)) / 8
(dz/dy) = -0.375
Taking the rate of change in the x and y direction for cell ‘e’, aspect is calculated using:
aspect = 57.29578 * atan2 (dz/dy, -dz/dx)
aspect = 57.29578 * atan2 (-0.375, 8.125)
aspect = -2.64
The above aspect value is then converted to values ranging in the compass directions (0 - 360 degrees) according to the following rule:
if aspect < 0
cell = 90.0 - aspect
else if aspect > 90.0
cell = 360.0 - aspect + 90.0
cell = 90.0 – aspect
Aspect = -2.64
aspect < 0
Cell = 90.0 - aspect
Cell = 90 – (-2.64)
Cell = 90 + 2.64
Cell = 92.64
The aspect value of 92 for cell ‘e’ = East.
Burrough, P. A. and McDonell, R.A., 1998. Principles of Geographical Information Systems (Oxford University Press, New York), p. 190.