Spatial enrichment: points meet polygons
Transform continues: enrichment. Silver observations know where they are, but not what they are *in*. Enrichment joins data to geography — each station gets its county (later: elevation zone, flood zone, H3 cell) — so gold can aggregate by place instead of by lonely point. The workhorse is the spatial join from Lesson 22, in GeoPandas this time.
The code
import geopandas as gpd
obs = gpd.read_parquet("lake/silver/observations/date=2026-11-12.parquet")
counties = gpd.read_parquet("counties.geoparquet")
assert obs.crs == counties.crs # same CRS, or the join lies
enriched = gpd.sjoin(obs, counties[["name", "geometry"]],
how="left", predicate="within")
unmatched = enriched["name"].isna().sum()
print(f"{unmatched} stations outside all counties")
In practice
Never loop points × polygons by hand. sjoin builds a spatial index (Lesson 29) over one side and tests only candidate pairs whose bounding boxes overlap, then runs the exact within test on those. Millions of points join in seconds because almost every pair is never compared.
how="left" keeps every observation. A station over water, or just outside the county file's coverage, gets a NaN county instead of disappearing. Then count the NaNs: the unmatched count is a quality signal, not an error to hide. If it suddenly jumps between runs, something upstream changed — a CRS, a boundary file, a source.
Enrichment is a pattern, not a place. County today, H3 cell tomorrow (Lesson 29's cell ID as a plain column is enrichment by grid instead of by polygon), flood zone next week. Each enrichment is one more column that downstream aggregation can group by.
Python bridge: ST_Contains in SQL (Lesson 22), sjoin in GeoPandas, Sedona at cluster scale (Lesson 26) — the same predicate wearing three engines' clothes.
Further reading
Merging data — GeoPandas user guide (the official guide to attribute joins vs spatial joins in GeoPandas, including sjoin predicates)
Try it
Practice question: After the join, 3 stations have a NaN county — yet on a map they clearly sit on land in New Jersey. Name the two most likely causes.
Show answer
Result: First suspect: a boundary case. A station sitting exactly on a county border is in neither polygon's interior, so within fails for both — switching the predicate to intersects, or falling back to sjoin_nearest, fixes it. Second suspect: the county file itself — a missing county or an outdated boundary vintage. (The CRS assert already rules out the third classic cause, mismatched coordinate systems.) Unmatched rows after a left join are a diagnostic, not noise: always count them, and investigate when the count moves.