Working with Terrain Data in QGIS

Download, process, visualize, and analyze elevation data using QGIS

A comprehensive guide to downloading terrain data from USGS, extracting contour lines, creating cross-sections, and 3D visualizations in QGIS
Author

Daniele Cannatella

Published

February 5, 2025

Tutorial: Working with Terrain Data in QGIS

Master the art of downloading, processing, and visualizing elevation data for professional GIS analysis.


Learning Objectives

By the end of this tutorial, you will be able to:

  • Download elevation data from USGS EarthExplorer
  • Process and merge multiple raster tiles into a single DEM
  • Extract contour lines from elevation data
  • Create cross-sections to visualize terrain profiles
  • Produce 3D visualizations of terrain using QGIS plugins

These skills are essential for terrain analysis, watershed modeling, and environmental planning.


Workflow Summary

This tutorial follows these key steps:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ STEP 1: Download & Prepare Data                     β”‚
β”‚ What: Acquire terrain data from USGS                β”‚
β”‚ Time: ~20 min                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ STEP 2: Extract Contour Lines                       β”‚
β”‚ What: Create elevation contours from raster         β”‚
β”‚ Time: ~25 min                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ STEP 3: Create Cross-Sections                       β”‚
β”‚ What: Generate terrain profile graphs               β”‚
β”‚ Time: ~20 min                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ STEP 4: 3D Visualization                            β”‚
β”‚ What: Create interactive 3D terrain views           β”‚
β”‚ Time: ~25 min                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ RESULT: Complete terrain analysis package           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Prerequisites & Requirements

Before you start, make sure you have:

  • QGIS 3.x or higher installed (free download from qgis.org)
  • Internet connection to access USGS EarthExplorer
  • Free USGS account (registration required)
  • Study area shapefile (provided or create your own)
  • Disk space for elevation data (~500 MB for typical study areas)

Knowledge assumed: - Basic QGIS interface familiarity - Understanding of shapefiles and projections - Comfort with raster and vector data concepts

⚠️ Important: The USGS EarthExplorer requires free registration. Create your account before starting this tutorial.


Data & Resources

Key resources you’ll need:

Resource Source Purpose
USGS EarthExplorer https://earthexplorer.usgs.gov Download SRTM elevation data
Study Area Shapefile Provided in tutorial materials Define your area of interest
QGIS Plugins Built-in Plugin Manager Profile Tool, Qgis2threejs

Optional supporting resources: - USGS Documentation: https://lpdaac.usgs.gov - SRTM Dataset Info: https://earthexplorer.usgs.gov - QGIS Manual: https://docs.qgis.org

⚠️ Registration required: Create a free USGS account at https://earthexplorer.usgs.gov


Step-by-Step Instructions

Step 1: Download & Prepare Terrain Data

What you’ll do: Access USGS EarthExplorer, upload your study area, and download SRTM elevation data tiles.

1.1 - Register and Access USGS EarthExplorer

Create a free USGS account and log in to the EarthExplorer platform. This is a critical first step as you cannot download data without authentication.

Navigation Steps

  1. Visit <https://earthexplorer.usgs.gov/
  2. Click β€œRegister” (if you don’t have an account)
  3. Fill in your details and verify your email
  4. Log in with your credentials

USGS EarthExplorer login page with registration link highlighted

1.2 - Prepare and Upload Your Study Area

Before downloading data, you need to define the extent of your area of interest. You’ll convert your shapefile to KML format and upload it to EarthExplorer.

In QGIS:

QGIS Menu Sequence

Layers Panel β†’ Right-click "study_area" layer 
  β†’ Export β†’ Save Layer As...

This opens the export dialog. Configure as follows:

  • Format: Keyhole Markup Language [KML]
  • Filename: Study_area.kml
  • CRS: Keep default (WGS 84)
  • Click OK

On EarthExplorer Website:

Web Browser Steps

Search Criteria 
  β†’ KML/Shapefile Upload 
  β†’ Select File 
  β†’ Choose your Study_area.kml

The map will update to show your study area boundary (typically highlighted in blue or green).

EarthExplorer interface showing KML upload dialog and study area on map

1.3 - Search and Download SRTM Data

Now search for elevation data within your study area boundaries.

Search for SRTM Data:

SRTM Data Search Process

Data Sets 
  β†’ Search "Digital Elevation" 
  β†’ Select "SRTM 1 Arc-Second Global" 
  β†’ Click Results

The system will display available tiles that intersect your study area. You’ll typically see 2-4 tiles depending on your area size.

Review and Download:

  • Preview Click the foot icon to see each tile’s extent
  • Select Format Choose GeoTIFF 1 Arc-second
  • Download Download all tiles that cover your area

Save the GeoTIFF files to a dedicated folder (e.g., data/elevation_raw/)

EarthExplorer showing SRTM tiles with preview footprints and download options


Step 2: Process and Merge Elevation Data

What you’ll do: Merge multiple raster tiles into a single DEM and reproject to your working coordinate system.

2.1 - Build Virtual Raster

The downloaded SRTM data comes as separate tiles. First, create a virtual raster that merges them.

In QGIS:

QGIS Raster Menu

Raster 
  β†’ Miscellaneous 
  β†’ Build Virtual Raster

Configuration:

Parameter Setting
Input layers All 4 SRTM tiles
Place each input file into a separate band ☐ Unchecked
Allow projection difference β˜‘ Checked
Nodata value -9999
Output file dem_virtual.vrt

Click Run to merge the tiles into a single virtual raster.

2.2 - Reproject to UTM Coordinates

The SRTM data is in geographic coordinates (WGS 84). Reproject it to a projected coordinate system for accurate area-based analysis.

QGIS Raster Menu

Raster 
  β†’ Projections 
  β†’ Warp (Reproject)

Configuration:

Parameter Setting
Input layer dem_virtual.vrt
Target CRS WGS 84 / UTM zone 32 N
Output file dem_reprojected.tif

Note: Adjust the UTM zone based on your location (32N for Europe, etc.)

2.3 - Clip to Study Area

Extract only the data for your study area to reduce file size and processing time.

QGIS Raster Menu

Raster 
  β†’ Extraction 
  β†’ Clip Raster by Extent

Configuration:

Parameter Setting
Input layer dem_reprojected.tif
Clipping extent Use Layer Extent β†’ study_area
Nodata value -9999
Output file dem_clipped.tif

Your processed DEM is now ready for analysis!


Step 3: Extract Contour Lines

What you’ll do: Generate contour lines from the elevation raster to visualize terrain topology.

3.2 - Generate Contour Lines

Now create vector contour lines from your elevation data.

QGIS Raster Menu

Raster 
  β†’ Extraction 
  β†’ Contour (Vector)

Configuration:

Parameter Setting Notes
Input layer dem_clipped.tif Use original or smoothed DEM
Interval between contours 10 Meters (adjust for your area)
Output file contour_lines_10m.shp Vector shapefile
Attribute name elevation Field storing elevation values

Click Run. You now have contour lines showing terrain elevation!

Pro Tip: For larger areas (>1000 kmΒ²), use a 20 or 25m interval to avoid overcrowding. For smaller areas (<100 kmΒ²), 5m intervals provide good detail.

QGIS map showing extracted contour lines in brown/orange color over the study area


Step 4: Create Cross-Sections

What you’ll do: Install the Profile Tool plugin and create terrain elevation profiles.

4.1 - Install Profile Tool Plugin

The Profile Tool creates interactive terrain cross-sections that show elevation changes along a line.

In QGIS:

QGIS Plugin Menu

Plugins 
  β†’ Manage and Install Plugins

In the Search box: - Type: β€œProfile tool” - Select: β€œProfile tool” (by Borys Jurgiel) - Click: Install Plugin

Wait for installation to complete, then click OK.

4.2 - Activate and Configure Profile Tool

QGIS Menu Sequence

Plugins 
  β†’ Profile tool 
  β†’ Terrain profile

A new Profile panel appears on the right side of QGIS.

Setup:

  1. In the Layers panel, select your DEM raster
  2. In the Profile panel, click β€œAdd Layer”
  3. Select β€œTemporary polyline” (or β€œActive layer polyline”)
  4. On the map, draw a line across the terrain where you want the cross-section

The elevation profile graph appears automatically in the Profile panel!

QGIS window with Profile Tool panel showing elevation graph and temporary polyline on DEM

Customize the Graph:

  • Right-click the graph to access export and configuration options
  • Adjust Y-axis to emphasize terrain relief
  • Export as PNG, PDF, or SVG for reports

Step 5: 3D Visualization

What you’ll do: Install Qgis2threejs plugin and create interactive 3D terrain views.

5.1 - Install Qgis2threejs Plugin

This plugin generates stunning 3D visualizations of your terrain data.

In QGIS:

QGIS Plugin Menu

Plugins 
  β†’ Manage and Install Plugins

In the Search box: - Type: β€œQgis2threejs” - Select the plugin by Minoru Akagi - Click: Install Plugin

The plugin installation may take 30-45 seconds. Click OK when complete.

5.2 - Create 3D Terrain View

Once installed, a new Web toolbar appears above your map.

QGIS Qgis2threejs Menu

Web 
  β†’ Qgis2threejs 
  β†’ Qgis2threejs Exporter

Configuration:

  1. DEM layer: Select dem_clipped.tif
  2. Color layer: Optional (use contour_lines for additional detail)
  3. Vertical exaggeration: 1.5-2.0 (exaggerates relief for visibility)
  4. Export format: HTML (for web) or Three.js (for advanced use)
  5. Output filename: terrain_3d.html

Click Export. Your 3D visualization opens in a web browser!

Interact with 3D view: - Rotate Click and drag - Zoom Scroll wheel - Pan Right-click and drag

3D terrain visualization in browser showing mountainous area with exaggerated relief and color gradient


Result & Expected Outcome

What you should have now:

βœ… Processed DEM ready for analysis
βœ… Vector contour lines showing terrain topology
βœ… Terrain cross-sections for elevation profiles
βœ… Interactive 3D visualization for presentations

Your final data package includes:

study_area_terrain/
β”œβ”€β”€ raw_data/
β”‚   β”œβ”€β”€ SRTM_tile_N50_E005.tif
β”‚   β”œβ”€β”€ SRTM_tile_N50_E006.tif
β”‚   β”œβ”€β”€ SRTM_tile_N51_E005.tif
β”‚   └── SRTM_tile_N51_E006.tif
β”œβ”€β”€ processed/
β”‚   β”œβ”€β”€ dem_virtual.vrt
β”‚   β”œβ”€β”€ dem_reprojected.tif
β”‚   β”œβ”€β”€ dem_clipped.tif
β”‚   └── dem_clipped_gauss.tif
β”œβ”€β”€ vectors/
β”‚   β”œβ”€β”€ contour_lines_10m.shp
β”‚   β”œβ”€β”€ contour_lines_10m.dbf
β”‚   β”œβ”€β”€ contour_lines_10m.shx
β”‚   └── contour_lines_10m.prj
β”œβ”€β”€ visualizations/
β”‚   β”œβ”€β”€ terrain_profile_section_A.png
β”‚   β”œβ”€β”€ terrain_profile_section_B.png
β”‚   └── terrain_3d.html
└── analysis_results/
    β”œβ”€β”€ elevation_statistics.csv
    └── slope_analysis.tif

What you can do next: - Perform slope and aspect analysis - Calculate watershed boundaries - Model hydrological flows - Plan infrastructure projects - Generate professional map layouts


Exercises & Challenges

Challenge 1: Intermediate - Extract Multiple Contour Intervals

🟑 Create Multi-Scale Contours Intermediate

Objective: Create contour maps at different intervals to understand when each is appropriate.

Your task:

  1. Generate contour lines at 5m interval and save as contour_5m.shp
  2. Generate contour lines at 25m interval and save as contour_25m.shp
  3. Compare both visually in QGIS
  4. Document which is better for your area and why

Hint: Use smaller intervals for detailed small-area analysis, larger intervals for regional overviews.

Solution (click to reveal):

For 5m contours:

Raster > Extraction > Contour
Input: dem_clipped.tif
Interval: 5
Output: contour_5m.shp

For 25m contours:

Raster > Extraction > Contour
Input: dem_clipped.tif
Interval: 25
Output: contour_25m.shp

Comparison: The 5m contours show detailed terrain variation ideal for engineering and detailed planning. The 25m contours are clearer for regional analysis and printed maps.


Challenge 2: Intermediate - Calculate Slope from DEM

🟑 Slope and Aspect Analysis Intermediate

Objective: Derive slope and aspect rasters from the DEM for terrain analysis.

Your task:

  1. Use Raster > Analysis > Slope on your DEM
  2. Use Raster > Analysis > Aspect on your DEM
  3. Apply a color ramp to visualize slope categories
  4. Identify areas of steep terrain (>30Β°)

Resources: - QGIS Raster Analysis: <https://docs.qgis.org/latest/en/docs/user_manual/processing_algs/qgis/rasteranalysis.html

Hint: Slope values >30Β° indicate steep terrain unsuitable for building but good for hydropower studies.


Tips, Tricks & Warnings

πŸ’‘ Pro Tips

  • Tip 1: Check data resolution - SRTM 1 Arc-Second has ~30m resolution. For smaller areas, consider ASTER GDEM (higher resolution) or LiDAR data.

  • Tip 2: Use virtual rasters - Building virtual rasters (VRT) keeps original data intact and processes faster than creating new files.

  • Tip 3: Smooth before contouring - Always apply a Gaussian filter before extracting contours. Smoothing removes noise artifacts and creates professional-looking contour maps.

  • Tip 4: Exaggerate vertical scale in 3D - Use 1.5-2.0x exaggeration in 3D visualizations to make subtle terrain variations visible in presentations.

  • Tip 5: Cache your processed data - Save clipped, reprojected DEMs so you don’t need to re-download raw tiles every time.

⚠️ Common Pitfalls

Watch out for these mistakes:

  1. Forgetting to reproject: SRTM data is in WGS 84 (geographic). Always reproject to UTM or local coordinates before analysis to get accurate measurements.

    ❌ Measuring in degrees = inaccurate distances
    βœ… Measure in UTM = accurate meters/kilometers
  2. Wrong contour intervals: Using 10m contours for a 100 kmΒ² region creates thousands of lines. Use 25-50m for large areas.

  3. Not checking Nodata values: SRTM often has -9999 for water bodies. Specify this or your analysis will be corrupted by these artificial values.

  4. Ignoring edge effects: Clipped DEMs have edge artifacts. Keep a buffer around your actual study area when downloading.

πŸ”΄ Critical Warnings

These mistakes could corrupt your analysis:

⚠️ Always backup original SRTM tiles before processing. Download once, work with copies:

# Recommended directory structure
β”œβ”€β”€ data_original/          ← Original SRTM (never modify)
β”‚   └── SRTM_*.tif
└── data_working/          ← Your processed versions
    β”œβ”€β”€ dem_virtual.vrt
    β”œβ”€β”€ dem_reprojected.tif
    └── dem_clipped.tif

⚠️ Verify your projection before publishing maps. Mistakes here are costly:

Check: Raster > Properties > Source 
βœ… Verify CRS shows "WGS 84 / UTM zone 32 N"
❌ Do NOT report results if CRS is uncertain

⚠️ Test contour extraction on small areas first before processing entire datasets. A failed 500MB process wastes hours.


References & Further Reading

Official Documentation

Tutorials & Guides

  1. β€œQGIS Raster Analysis” - QGIS Documentation (Official)
    • Comprehensive guide to raster processing tools
    • Available: https://docs.qgis.org/
  2. β€œSRTM Data and Terrain Analysis” - USGS Guide (2020)
    • Technical specifications and best practices
    • Available: https://lpdaac.usgs.gov/

Plugin Documentation

  • Profile Tool Plugin: https://github.com/borisj/ProfileTool
    • GitHub repository with examples and troubleshooting
  • Qgis2threejs Plugin: https://qgis2threejs.readthedocs.io/
    • Complete documentation with advanced 3D options

Questions or Issues?

If you encounter problems:

  1. Check QGIS compatibility - Ensure you’re running QGIS 3.0 or newer
  2. Verify USGS account - Registration required for all downloads
  3. Check internet connection - EarthExplorer requires stable connection
  4. Search QGIS Documentation - https://docs.qgis.org/
  5. Ask on GIS Stack Exchange - https://gis.stackexchange.com/

Common issues:

Issue Solution
Plugin won’t install Update QGIS to latest version
β€œNodata” artifacts in contours Check nodata value is set to -9999
3D visualization very slow Use larger contour intervals (25-50m)
Projection mismatches Always reproject to UTM before analysis

Tutorial Version: 1.0
Last Updated: February 5, 2025
Difficulty: Intermediate
Estimated Duration: 90 minutes
Status: βœ… Complete and tested in QGIS 3.28.0

Back to top