Gradient, Aspect, and Direction of Steepest Descent
Partial derivatives in action on terrain surfaces
Before You Start
You should know
What a digital elevation model is and how slope measures change from one place to another.
You will learn
How terrain steepness and direction are calculated, what a gradient means, and why water and gravity tend to follow steepest descent.
Why this matters
This chapter turns stored elevation into motion and process. It is a key bridge from map data to hydrology, erosion, and landform analysis.
If this gets hard, focus on…
The physical picture: the gradient points uphill fastest, and steepest descent points downhill fastest. Hold onto that picture first.
Ask a backcountry skier where the avalanche risk is concentrated on a particular slope and they will immediately name the aspect — north-facing or south-facing, shallow or steep. They are, without knowing it, estimating the gradient vector. The orientation of erosion rills, the direction of hillslope seepage, the angle at which a cut slope was designed — all these encode the same two quantities: the rate of elevation change with horizontal distance, and the compass direction in which that rate is greatest.
The gradient is the multivariable calculus tool that turns a terrain surface into a set of directional instructions. Computed from a digital elevation model using finite differences — a simple arithmetic operation applied to a 3×3 window of elevation values — it gives you simultaneously how steep any cell is and which way it faces. Slope is the gradient’s magnitude. Aspect is its direction. Water flows opposite to the gradient, toward the lowest available neighbour. These three derived quantities underpin almost everything in terrain analysis: flow routing, viewshed calculation, solar irradiance mapping, mass movement susceptibility. This model shows how to compute them from first principles.
1. The Question
Given a digital elevation model, how do we calculate: 1. Slope — how steep is the terrain? 2. Aspect — which direction does the slope face? 3. Flow direction — which way would water flow?
All three questions have the same answer: compute the gradient.
The gradient is a vector pointing in the direction of steepest ascent, with magnitude equal to the rate of ascent. Water flows opposite the gradient (downhill). Slope is the gradient’s magnitude. Aspect is the gradient’s direction.
The mathematical question: How do we compute the gradient from a grid of elevation values?
2. The Conceptual Model
Partial Derivatives: Slope in Each Direction
For a continuous surface z = f(x, y), the partial derivatives measure how elevation changes when you move in one direction:
\frac{\partial z}{\partial x} = \text{rate of change in the east-west direction}
\frac{\partial z}{\partial y} = \text{rate of change in the north-south direction}
Example: If \frac{\partial z}{\partial x} = 0.05 (dimensionless, or m/m), then elevation increases by 0.05 meters for every meter you move eastward.
The Gradient Vector
The gradient combines both partial derivatives into a vector:
\nabla z = \left(\frac{\partial z}{\partial x}, \frac{\partial z}{\partial y}\right)
Properties:
- Direction: Points in the direction of steepest ascent
- Magnitude: Rate of ascent in that direction (steepest slope)
Slope and Aspect from the Gradient
Slope (steepness):
S = |\nabla z| = \sqrt{\left(\frac{\partial z}{\partial x}\right)^2 + \left(\frac{\partial z}{\partial y}\right)^2}
Units: dimensionless (rise/run) or degrees/percent
Aspect (direction the slope faces):
\theta = \arctan2\left(\frac{\partial z}{\partial y}, \frac{\partial z}{\partial x}\right)
Measured clockwise from north (geographic convention): - 0° = north - 90° = east - 180° = south - 270° = west
The Gradient Is A Directional Instruction
One hillside gives three linked answers at once: which way is uphill fastest, which way is downhill fastest, and which compass direction the slope faces.
Read the picture in this order
- The blue arrow points toward the fastest uphill increase in elevation. That is the gradient.
- The red arrow points exactly the opposite way. That is steepest descent, which is the first-order flow direction.
- The slope is the size of the blue arrow. Bigger arrow means steeper terrain.
- The aspect is the compass-facing direction of the downhill slope, not just a raw angle from the x-axis.
Shortcut: if you can picture a ball rolling off the surface, you already understand why the gradient matters.
3. Building the Mathematical Model
Finite Differences: Approximating Derivatives
A DEM gives us discrete elevation values z_{i,j}. We don’t have a formula for z(x, y), so we can’t compute derivatives analytically.
Solution: Approximate derivatives using finite differences — the discrete analog of derivatives.
Central difference (most accurate for interior cells):
\frac{\partial z}{\partial x} \approx \frac{z_{i, j+1} - z_{i, j-1}}{2 \Delta x}
\frac{\partial z}{\partial y} \approx \frac{z_{i+1, j} - z_{i-1, j}}{2 \Delta y}
Where \Delta x and \Delta y are the cell sizes (often equal: \Delta x = \Delta y = d).
Interpretation: The derivative in the x-direction is approximated by the elevation difference between the cells to the east and west, divided by the distance between them.
The 3×3 Neighborhood
For cell (i, j), the central difference uses a 3×3 window:
z[i-1,j-1] z[i-1,j] z[i-1,j+1]
z[i,j-1] z[i,j] z[i,j+1]
z[i+1,j-1] z[i+1,j] z[i+1,j+1]
Horn’s method (commonly used in GIS software) weights diagonal neighbors:
\frac{\partial z}{\partial x} = \frac{(z_{i-1,j+1} + 2z_{i,j+1} + z_{i+1,j+1}) - (z_{i-1,j-1} + 2z_{i,j-1} + z_{i+1,j-1})}{8 \Delta x}
\frac{\partial z}{\partial y} = \frac{(z_{i+1,j-1} + 2z_{i+1,j} + z_{i+1,j+1}) - (z_{i-1,j-1} + 2z_{i-1,j} + z_{i-1,j+1})}{8 \Delta y}
This is a weighted average that reduces noise.
Computing Slope and Aspect
Once you have \frac{\partial z}{\partial x} and \frac{\partial z}{\partial y}:
Slope (in radians):
S_{\text{rad}} = \arctan\left(\sqrt{\left(\frac{\partial z}{\partial x}\right)^2 + \left(\frac{\partial z}{\partial y}\right)^2}\right)
Slope (in degrees):
S_{\text{deg}} = S_{\text{rad}} \times \frac{180}{\pi}
Slope (as percent):
S_{\%} = \sqrt{\left(\frac{\partial z}{\partial x}\right)^2 + \left(\frac{\partial z}{\partial y}\right)^2} \times 100
Aspect (in degrees from north):
A = 90° - \arctan2\left(\frac{\partial z}{\partial y}, \frac{\partial z}{\partial x}\right) \times \frac{180}{\pi}
(Adjust to ensure 0^\circ \leq A < 360^\circ)
4. Worked Example by Hand
Problem: A 3×3 DEM with cell size d = 10 m:
100 105 110
102 107 112
105 110 115
Calculate slope and aspect at the center cell (i=1, j=1) using central differences.
Solution
Cell values:
- z_{0,0} = 100, z_{0,1} = 105, z_{0,2} = 110
- z_{1,0} = 102, z_{1,1} = 107, z_{1,2} = 112
- z_{2,0} = 105, z_{2,1} = 110, z_{2,2} = 115
Partial derivative in x (east-west):
\frac{\partial z}{\partial x} = \frac{z_{1,2} - z_{1,0}}{2 \Delta x} = \frac{112 - 102}{2 \times 10} = \frac{10}{20} = 0.5
Partial derivative in y (north-south):
\frac{\partial z}{\partial y} = \frac{z_{2,1} - z_{0,1}}{2 \Delta y} = \frac{110 - 105}{2 \times 10} = \frac{5}{20} = 0.25
Slope magnitude:
S = \sqrt{(0.5)^2 + (0.25)^2} = \sqrt{0.25 + 0.0625} = \sqrt{0.3125} \approx 0.559
Slope in degrees:
S_{\text{deg}} = \arctan(0.559) \times \frac{180}{\pi} \approx 29.2°
Aspect:
\theta_{\text{raw}} = \arctan2(0.25, 0.5) \times \frac{180}{\pi} \approx 26.6°
Convert to geographic aspect (clockwise from north):
A = 90° - 26.6° = 63.4°
The slope is 29.2° steep and faces 63.4° (ENE — slightly east of northeast).
5. Computational Implementation
Below is an interactive model computing slope and aspect from a synthetic DEM.
Try this:
- Plane: Uniform slope and aspect (constant gradient everywhere)
- Cone: Slope increases toward the peak; aspect radiates outward
- Ridge: High slope along the ridge flanks; aspect points away from the ridgeline
- Valley: Aspect points toward the valley axis
- Saddle: Aspect flips 180° across the saddle point
Key insight: The gradient captures both the magnitude (slope steepness) and direction (aspect) of the terrain’s tilt at every point.
6. Interpretation
Slope Units
Rise/run (dimensionless): \frac{\Delta z}{\Delta x} = 0.1 means 0.1 m rise per 1 m horizontal distance.
Degrees: \arctan(0.1) \approx 5.7°
Percent: 0.1 \times 100 = 10\%
Conversion:
- Gentle: <5° or <9%
- Moderate: 5–15° or 9–27%
- Steep: 15–30° or 27–58%
- Very steep: >30° or >58%
Aspect and Solar Radiation
Aspect determines insolation (solar radiation received): - Equator-facing slopes (south in N. Hemisphere, north in S. Hemisphere): maximum energy - Pole-facing slopes: minimum energy - East/west slopes: intermediate
This creates microclimates — different vegetation, soil moisture, snow persistence.
Flow Direction
Water flows downhill — opposite the gradient direction.
If \nabla z = (0.5, 0.25) (pointing ENE uphill), then flow direction is (-0.5, -0.25) (pointing WSW downhill).
Next model (Model 9) will use this to route water across a DEM.
7. What Could Go Wrong?
Edge Effects
Cells on the edge of a DEM have no neighbors beyond the boundary. Central differences require neighbors on both sides.
Solutions:
- Mark edge cells as “no data”
- Use forward/backward differences at edges (less accurate)
- Extend the DEM artificially (mirror, clamp values)
Noisy DEMs
Real DEMs contain measurement errors. Small errors can produce large swings in slope when differencing nearby cells.
Solutions:
- Smooth the DEM first (e.g., Gaussian filter)
- Use weighted finite differences (Horn’s method)
- Increase cell size (aggregate to coarser resolution)
Coordinate System Issues
If \Delta x \neq \Delta y (non-square cells), use separate cell sizes in the x and y derivatives.
If using geographic coordinates (lat/lon), the distance per degree varies with latitude. Convert to a projected coordinate system first.
Flat Areas
If \frac{\partial z}{\partial x} = \frac{\partial z}{\partial y} = 0, the gradient is zero: - Slope is 0° - Aspect is undefined (no preferred direction)
GIS software often assigns flat areas an aspect of -1 or 360°.
8. Extension: The Gradient as a Vector Field
The gradient \nabla z assigns a vector to every point in the plane. This is a vector field.
Visualization: At each grid point, draw an arrow: - Direction: Points uphill (steepest ascent) - Length: Proportional to slope magnitude
Properties:
- Gradient vectors are perpendicular to contour lines (level curves of constant elevation)
- Water flows along streamlines — curves tangent to the negative gradient
This geometric view connects calculus, vector analysis, and physical flow.
9. Math Refresher: Partial Derivatives
Notation
For z = f(x, y):
\frac{\partial z}{\partial x} = \frac{\partial f}{\partial x} = f_x
Read as: “the partial derivative of z with respect to x.”
How to Compute (Analytically)
Treat y as a constant, differentiate with respect to x:
Example: z = x^2 + 3xy + y^2
\frac{\partial z}{\partial x} = 2x + 3y
\frac{\partial z}{\partial y} = 3x + 2y
Geometric Interpretation
\frac{\partial z}{\partial x} is the slope of the surface in the x-direction (holding y constant).
Imagine slicing the surface with a vertical plane parallel to the x-axis — the cross-section is a curve, and \frac{\partial z}{\partial x} is its slope.
Summary
- The gradient \nabla z = \left(\frac{\partial z}{\partial x}, \frac{\partial z}{\partial y}\right) points in the direction of steepest ascent
- Slope is the magnitude: S = |\nabla z|
- Aspect is the direction: A = \arctan2\left(\frac{\partial z}{\partial y}, \frac{\partial z}{\partial x}\right)
- Finite differences approximate partial derivatives from a DEM
- Central differences: \frac{\partial z}{\partial x} \approx \frac{z_{i,j+1} - z_{i,j-1}}{2\Delta x}
- Water flows downhill — opposite the gradient
- Aspect creates microclimates; slope affects erosion, stability, and runoff