1Learning Objectives
- Join attribute tables to spatial data using
.merge() - Filter GeoDataFrames using attribute queries
- Perform spatial joins using
gpd.sjoin() - Create buffer zones around infrastructure features
- Clip spatial data to a study area boundary
- Compute spatial aggregations using
.dissolve()and.groupby() - Build interactive web maps with
.explore()
2Engineering Scenario
You are a graduate engineer at a consulting firm assessing coastal infrastructure exposure for the Christchurch City Council. Your task is to determine which buildings, roads, and communities are at risk from sea-level rise in the 0–5 m elevation zone. You will combine census, infrastructure, and hazard data to produce an exposure report.
conda activate encn205, then jupyter lab,
then open Lab2_VectorAnalysis.ipynb and run the cells in order with
Shift + Enter.3Step-by-Step Instructions
Section 1: Setup and Data Creation
Load libraries and the Christchurch coastal zone datasets — buildings, pipes, statistical areas, and a coastal hazard zone.
Section 2: Attribute Queries
Filter GeoDataFrames by attribute values. Identify residential buildings in the low-elevation
zone. Practice combining multiple filter conditions with & and | operators.
Section 3: Table Joins (.merge())
Merge a valuation table (plain DataFrame) to buildings (GeoDataFrame) using a shared key. Verify the result retains geometry. Map buildings by capital value.
Section 4: Spatial Joins (gpd.sjoin())
Assign each building to its statistical area using a spatial join. Summarise building counts and values per area. Practice spatial join with pipe data.
Section 5: Buffer Analysis
Create 50 m buffer zones around pipes. Use a spatial join to find buildings within buffer zones. Understand how buffer distance depends on CRS units.
Section 6: Clipping
Extract buildings within a focus area boundary using gpd.clip(). Compare the full
dataset to the clipped result.
Section 7: Dissolve and Aggregation
Merge statistical areas by deprivation category. Aggregate population and other attributes. Compare individual vs dissolved maps.
Section 8: Interactive Maps
Create interactive web maps with .explore(). Add multiple layers, tooltips, and
popups. Experiment with different basemap tiles.
Section 9: Exposure Assessment
Combine all techniques: filter at-risk buildings, spatial join to areas, summarise by deprivation level. Produce a final exposure map and summary table.
4Assessment: Lab Sign-Off
Step 1 — Self-check
Before you start the quiz, make sure you can do each of these:
- Loaded a multi-layer GeoPackage and described its contents
- Performed attribute queries to filter features by multiple criteria
- Completed a spatial join and explained how it differs from a table join
- Created buffer zones and identified affected buildings
- Produced the exposure summary table by deprivation level
- Created at least one interactive map using
.explore()
Step 2 — Take the sign-off quiz
- Download Lab2_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_Lab2_<yourID>.png.
Step 3 — Submit
Upload ENCN205_Lab2_<yourID>.png to the Lab 2 Sign-Off
submission on LEARN.
Tips and Troubleshooting
| Symptom | Fix |
|---|---|
| Spatial join returns empty | Check both layers have the same CRS |
.explore() fails |
conda install -c conda-forge folium mapclassify |
| Buffer distances look wrong | Always buffer in a projected CRS (EPSG:2193), never geographic (EPSG:4326) |
dissolve fails |
Check for None/NaN values in the grouping column |
| Unsure what an operation returned | Use type(result) to verify you still have a GeoDataFrame |