Remark
These lecture notes are in early access and will continue to evolve as examples are tested with new data releases.
Section goal
Move from a stored layer to a defensible spatial answer: identify the data type, choose an operation that matches the question, and validate the result before interpreting it.
4. Vector Data Operations and Spatial Analysis#
Chapter 1 introduced geographic data models and coordinate reference systems (CRS). Chapter 2 developed the spatial reference concepts behind those models, and Chapter 3 showed how geospatial data are stored and exchanged. This chapter uses those foundations to analyze Calgary’s parks, libraries, LRT stations, tracks, and community districts with GeoPandas and Shapely.
The core sections follow a repeatable workflow:
identify the geometry and attributes that answer the question;
inspect the source schema, CRS, geometry types, and missing values;
choose a geometric operation, predicate, join, or overlay;
use a projected CRS for metric measurements;
check row counts, geometry validity, units, and edge cases; and
record the source, date, assumptions, and output.
Data types in the running example
Data type |
Repository example |
What it supports |
|---|---|---|
Point |
Library and LRT station locations |
Locations, containment, proximity, and nearest-feature questions |
LineString |
LRT tracks |
Length, intersections, and corridor analysis |
Polygon/MultiPolygon |
Parks, city boundary, and community districts |
Area, containment, clipping, and overlay analysis |
Tabular data |
Library attributes and district records |
Keys, filtering, summaries, and attribute joins |
Raster |
NDVI and other gridded surfaces |
Values summarized within vector features |
The source files use different encodings: library locations and LRT geometries are stored as text in CSV columns, while parks are GeoJSON and the city boundary is a GeoPackage. Reading a file is only the first step; preserve the original values and make every conversion explicit.
A compact validation checklist
Before trusting a map or statistic, ask:
Does every layer have the CRS I expect?
Are the geometry type and spatial predicate appropriate to the question?
Are distances, lengths, and areas calculated in meaningful units?
Did a join or overlay change the number of rows, and is that change explained?
Are empty, missing, invalid, or duplicated features reported?