1Learning Objectives
- Load and inspect raster data (DEMs) held as numpy arrays
- Visualise elevation data with a hillshade overlay
- Perform map algebra: reclassification, masking, arithmetic
- Compute terrain derivatives: slope and aspect
- Crop raster data using vector boundaries
- Extract raster values at point locations (buildings)
- Compute zonal statistics (mean elevation per zone)
- Combine raster hazard data with vector building data
2Engineering Scenario
You are analysing terrain on Banks Peninsula for a slope stability and seismic hazard assessment. Using a real 8 m DEM, you will compute terrain derivatives, identify steep slopes on the volcanic flanks, and extract ground shaking intensities at building locations.
conda activate encn205, then jupyter lab,
then open Lab3_RasterAnalysis.ipynb and run the cells in order with
Shift + Enter.3Step-by-Step Instructions
Section 1: Setup and Raster Fundamentals
Import numpy, matplotlib, and geopandas. Understand raster fundamentals: cells, resolution, and extent.
Section 2: Loading and Inspecting the DEM
Load the Banks Peninsula DEM. Inspect its shape, resolution, and elevation range. Visualise it with a terrain colourmap.
Section 3: Hillshade — Simulating Terrain Illumination
Compute hillshade from elevation gradients. Combine the DEM and hillshade for enhanced visualisation, and try different sun azimuths.
Section 4: Map Algebra — Reclassification and Masking
Reclassify elevation into engineering-relevant classes. Create Boolean masks for flood zones. Calculate areas.
Section 5: Terrain Derivatives — Slope and Aspect
Compute slope (steepness) and aspect (direction). Identify steep slopes above a threshold and calculate the steep area.
Section 6: Cropping Rasters with Vector Boundaries
Crop the DEM to a study area polygon boundary. Compare the full and cropped raster extents.
Section 7: Extracting Raster Values at Point Locations
Extract elevation and slope values at building locations. Write a function that maps point coordinates to raster cells.
Section 8: Combining Raster and Vector — Seismic Hazard Assessment
Create a PGA raster. Extract shaking intensity at buildings. Classify damage potential and produce a final assessment map.
Section 9: Zonal Statistics
Divide the study area into zones. Compute mean, max, and range statistics per zone. Visualise zone boundaries on the DEM.
Section 10: Elevation Distribution (Hypsometric Curve)
Plot the elevation histogram and hypsometric curve. Interpret what the curve shape says about Banks Peninsula's terrain compared to a flat alluvial plain.
4Assessment: Lab Sign-Off
Step 1 — Self-check
Before you start the quiz, make sure you can do each of these:
- Loaded and inspected the real Banks Peninsula DEM
- Created hillshade visualisations with different sun angles
- Performed reclassification and masking operations
- Computed slope and identified steep areas on the volcanic flanks
- Extracted raster values at building locations
- Completed the seismic hazard assessment with damage classification
- Computed zonal statistics and interpreted the results
Step 2 — Take the sign-off quiz
- Download Lab3_SignOff.html from LEARN and open it in your web browser.
- Enter your full name and University ID, then answer the 10 questions.
- You need 8 out of 10 to pass. You can retake it as often as you like — each attempt draws a new set of questions, and every answer comes with an explanation.
- When you pass, click Download Sign-Off PNG. This saves a file called
ENCN205_Lab3_<yourID>.png.
Step 3 — Submit
Upload ENCN205_Lab3_<yourID>.png to the Lab 3 Sign-Off
submission on LEARN.
Tips and Troubleshooting
| Symptom | Fix |
|---|---|
imshow shows the DEM upside-down |
Use the origin='lower' parameter |
| Colours look wrong | Check for NaN values in your array |
| Slope values look far too small or large | np.degrees() converts radians to degrees |
| Point extraction returns the wrong cell | Array indexing is row = (y - y_origin) / resolution,
col = (x - x_origin) / resolution |
| Shape errors when combining arrays | Check the array shape — a DEM is (rows, cols), not (cols, rows) |
| Working with your own data later | For real projects, use rioxarray to read GeoTIFF files |