Gis, Qgis, ArcGis  Experts Just a Click Away

Terrain analysis involves extracting useful information from elevation data, typically using a Digital Elevation Model (DEM). Three of the most common terrain analysis outputs are:

1. Slope

  • Definition: Measures the steepness or degree of incline of a surface.
  • Units: Expressed in degrees or percent rise.
  • Use cases:
    • Erosion studies
    • Construction planning
    • Agriculture (e.g., drainage management)

2. Aspect

  • Definition: The compass direction that a slope faces (e.g., north, southeast).
  • Units: Degrees from 0 (north) to 360 (back to north).
  • Use cases:
    • Solar radiation modeling
    • Vegetation distribution
    • Microclimate mapping

3. Hillshade

  • Definition: A visual representation of the terrain that simulates shadows cast by the sun.
  • Parameters:
    • Azimuth: Direction of the light source (e.g., 315° = NW)
    • Altitude: Angle of the sun above the horizon
  • Use cases:
    • Map aesthetics
    • Terrain visualization
    • Identifying landforms

Tools for Terrain Analysis:

You can perform terrain analysis using:

  • QGIS (open-source GIS software)
    • Use the “Raster → Analysis” tools
    • Plugins like SAGA or GRASS
  • ArcGIS Pro
    • Use Spatial Analyst or 3D Analyst
  • Python:
    • Libraries like rasterio, numpy, matplotlib, GDAL, and richdem
  • Google Earth Engine (for large-scale or cloud-based DEM analysis)

See Code Examples in Python

Here’s a full Python example using commonly used libraries like rasterio, numpy, and matplotlib to perform slope, aspect, and hillshade analysis on a DEM file:

Required Libraries

Install these if you haven’t yet:

bashCopyEditpip install rasterio numpy matplotlib
Here's a full Python example using commonly used libraries like rasterio, numpy, and matplotlib to perform slope, aspect, and hillshade analysis on a DEM file:

🔧 Required Libraries
Install these if you haven't yet:

bash
Copy
Edit
pip install rasterio numpy matplotlib
📜 Python Code
python
Copy
Edit
import rasterio
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LightSource

# Load DEM
dem_path = "your_dem.tif"
with rasterio.open(dem_path) as src:
    dem = src.read(1)
    transform = src.transform

# Get resolution
xres = transform[0]
yres = -transform[4]

# Compute gradients
dy, dx = np.gradient(dem, yres, xres)

# ------------------------
# 1. SLOPE (in degrees)
# ------------------------
slope = np.degrees(np.arctan(np.sqrt(dx**2 + dy**2)))

# ------------------------
# 2. ASPECT (azimuthal direction)
# ------------------------
aspect = np.degrees(np.arctan2(-dx, dy))
aspect = np.where(aspect < 0, 360 + aspect, aspect)

# ------------------------
# 3. HILLSHADE
# ------------------------
ls = LightSource(azdeg=315, altdeg=45)
hillshade = ls.hillshade(dem, vert_exag=1, dx=xres, dy=yres)

# ------------------------
# Plotting
# ------------------------
fig, axs = plt.subplots(1, 3, figsize=(18, 6))

axs[0].imshow(slope, cmap='terrain')
axs[0].set_title("Slope (degrees)")
axs[0].axis('off')

axs[1].imshow(aspect, cmap='hsv')
axs[1].set_title("Aspect (degrees)")
axs[1].axis('off')

axs[2].imshow(hillshade, cmap='gray')
axs[2].set_title("Hillshade")
axs[2].axis('off')

plt.tight_layout()
plt.show()
📁 Replace This:
python
Copy
Edit
dem_path = "your_dem.tif"
With the path to your actual DEM file.

Leave a Reply

Gabby Jones

Typically replies within a minute

Hello, Welcome to the site. Please click below button for chating me throught WhatsApp.