Raster Analysis

General raster analysis covers a broad set of cell-based operations: local algebra on single rasters, focal statistics across neighbourhoods, zonal summaries within polygon regions, reclassification, and suitability scoring. These tools form the computational backbone of many GIS modelling workflows.

This chapter demonstrates an environmental suitability analysis that combines multiple raster datasets through reclassification and weighted overlay.


Key Concepts

  • Local operations: Applied to each cell independently — arithmetic, logic, trigonometry, conditional assignment. Result depends only on the cell's own value (and corresponding cells in other input rasters).
  • Focal operations: Applied to each cell using values within a spatial neighbourhood (kernel). Examples: focal mean, focal max, focal standard deviation.
  • Zonal statistics: Aggregate raster values by zone boundaries defined by a second raster or vector polygon layer.
  • Reclassification: Map old cell values to new values via a lookup table or range intervals. Core step in suitability and habitat modelling.
  • Weighted overlay: Combine multiple reclassified factor rasters using factor-specific weights. The weighted sum produces a composite suitability score.
  • NoData / null handling: Cells with NoData propagate through most local operations. Ensure all input rasters share the same extent, resolution, and NoData mask before combining them.

End-to-End Workflow: Multi-Criteria Habitat Suitability

This workflow scores terrain for habitat suitability using slope, TWI, and distance from water as factors.

Inputs

LayerFormatNotes
slope.tifGeoTIFF rasterDegrees, from terrain analysis
twi.tifGeoTIFF rasterTopographic Wetness Index
streams.tifGeoTIFF rasterBinary stream network

All rasters must share the same projected CRS, extent, and cell size before being combined. Use Snap Raster Extents or QGIS Warp (Reproject) to align if needed.


Step 1 — Compute Distance from Water

Processing Toolbox → Whitebox Workflows → GIS Analysis → Euclidean Distance

ParameterRecommended value
Input featurestreams.tif
Outputdist_water.tif

Cells closer to water receive smaller values. This will be reclassified so that proximity = higher suitability.


Step 2 — Reclassify Slope Factor

Assign suitability scores 1–5 to slope ranges.

Processing Toolbox → Whitebox Workflows → Raster Analysis → Reclass

ClassSlope range (°)Suitability score
1> 301 (unsuitable)
220–302
310–203
45–104
50–55 (most suitable)

Use Reclass From File with a two-column table file (old value; new value) or set up intervals in the tool dialogue.

ParameterRecommended value
Input rasterslope.tif
Reclass intervals fileslope_reclass.txt
Outputslope_reclass.tif

Step 3 — Reclassify TWI Factor

ClassTWI rangeSuitability score
1< 41
24–62
36–83
48–104
5> 105
Processing Toolbox → Whitebox Workflows → Raster Analysis → Reclass
Input: twi.tif → Output: twi_reclass.tif

Step 4 — Reclassify Distance from Water

Closer = more suitable:

ClassDistance range (m)Suitability score
1> 5001
2300–5002
3100–3003
450–1004
50–505
Processing Toolbox → Whitebox Workflows → Raster Analysis → Reclass
Input: dist_water.tif → Output: dist_water_reclass.tif

Step 5 — Weighted Overlay (Raster Calculator)

Combine the three factors using assigned weights (must sum to 1.0).

FactorWeight
Slope suitability0.4
TWI suitability0.35
Distance suitability0.25

QGIS Raster Calculator:

("slope_reclass@1" * 0.4) + ("twi_reclass@1" * 0.35) + ("dist_water_reclass@1" * 0.25)

Output: suitability.tif (range 1–5, continuous).


Step 6 — Zonal Statistics (Optional)

Summarise suitability scores by catchment polygon.

Processing Toolbox → QGIS → Vector Analysis → Zonal Statistics (QGIS native)

ParameterRecommended value
Input rastersuitability.tif
Vector layerwatersheds.shp
StatisticsMean, Max, Std Dev
Output column prefixsuit_

Python Console Equivalent

import processing

# Step 1: distance from water
processing.run('whitebox_workflows:euclidean_distance', {
    'input': '/data/streams.tif',
    'output': '/data/dist_water.tif',
})

# Step 2–4: reclassify each factor
for src, dst in [
    ('slope', 'slope_reclass'),
    ('twi', 'twi_reclass'),
    ('dist_water', 'dist_water_reclass'),
]:
    processing.run('whitebox_workflows:reclass_from_file', {
        'input': f'/data/{src}.tif',
        'reclass_vals': f'/data/{src}_reclass.txt',
        'output': f'/data/{dst}.tif',
    })

# Step 5: weighted overlay via Raster Calculator
processing.run('qgis:rastercalculator', {
    'EXPRESSION': '("slope_reclass@1" * 0.4) + ("twi_reclass@1" * 0.35) + ("dist_water_reclass@1" * 0.25)',
    'LAYERS': [
        '/data/slope_reclass.tif',
        '/data/twi_reclass.tif',
        '/data/dist_water_reclass.tif',
    ],
    'OUTPUT': '/data/suitability.tif',
})

print("Suitability analysis complete.")

Advanced: Focal Statistics

Focal statistics smooth or enhance spatial patterns at a neighbourhood scale.

Processing Toolbox → Whitebox Workflows → Raster Analysis → Mean Filter

ParameterRecommended value
Input rastersuitability.tif
Filter size X5 (cells)
Filter size Y5
Outputsuitability_smooth.tif

Use Standard Deviation Filter to highlight areas of high local variability, or Percentile Filter for rank-based neighbourhood smoothing.


Common Pitfalls

ProblemLikely causeFix
Raster Calculator outputs all NoDataRasters have different extents or CRSClip/warp all inputs to common grid before combining
Reclass produces unexpected valuesRange gaps or overlaps in reclass tableVerify that intervals are contiguous with no gap or overlap
Zonal statistics returns wrong polygon countsRaster–vector CRS mismatchReproject vector to match raster CRS before running
Weighted overlay result > 5Weights do not sum to 1.0Recalculate weights so they sum to exactly 1.0
Focal filter introduces edge NoDataKernel extends beyond raster boundaryPad raster with Expand Raster before filtering, or ignore edge cells

Validation Checklist

  • All input rasters aligned (same CRS, extent, cell size, NoData value).
  • Reclass table covers the full observed value range with no gaps.
  • Weighted overlay weights sum to 1.0.
  • Output suitability range matches expected 1–5 interval.
  • Zonal statistics polygon CRS matches raster CRS.
  • Focal filter kernel size is appropriate for target feature scale.