Skip to content

Add OSM building footprint fetcher to exposure module#9

Merged
rehsani merged 1 commit into
mainfrom
step-3d-osm
May 4, 2026
Merged

Add OSM building footprint fetcher to exposure module#9
rehsani merged 1 commit into
mainfrom
step-3d-osm

Conversation

@rehsani
Copy link
Copy Markdown
Owner

@rehsani rehsani commented May 4, 2026

Summary

  • New exposure/osm.py: get_osm_buildings(lat, lon, buffer_deg, ...) -> BuildingCollection. Queries the Overpass API for OSM way["building"] elements inside the bbox.
  • New dataclasses in exposure/models.py:
    • BuildingFootprint (frozen; immutable polygon and tags)
    • BuildingCollection (sequence + total_area_m2() helper)
  • Polygon area uses a local equirectangular projection with cos(lat) at the polygon centroid — sub-0.1% error at building scale, well below OSM's source-data noise.
  • Public parse_overpass_response(payload) lets tests load saved JSON without touching the network.

Notable: stdlib-only

Implemented with urllib, json, mathno new dependency on osmnx, geopandas, or shapely. If we later need vector ops (rasterize / spatial joins for damage estimation against HAND), we'll add geopandas then.

Test plan

  • CI green on Linux runner.
  • Offline subset: 10 new tests via the committed 32 KB Robit Bata Overpass JSON fixture (35 buildings, 4,129 m² total, largest is the village church).
  • One integration test queries Overpass live for central Vaduz; defensive len > 10 so OSM edits don't break it.

Pipeline progress

  • Step 3d (part 1) — Multi-continent / multi-class JRC curves
  • Step 3d (part 2) — WorldPop population
  • Step 3d (part 3) — OSM building footprints (this PR)

New exposure/osm.py: get_osm_buildings(lat, lon, buffer_deg, ...) ->
BuildingCollection. Queries the Overpass API for OSM way["building"]
elements inside the bbox and returns each as a BuildingFootprint with
its (lat, lon) polygon, area in m^2, OSM id, and tags.

Models added to exposure/models.py:
- BuildingFootprint (frozen dataclass; immutable polygon and tags)
- BuildingCollection (sequence + total_area_m2 helper)

Polygon area uses a local equirectangular projection with a cos(lat)
factor at the polygon centroid. Building-scale polygons see sub-0.1%
error from this approximation, well below the noise of OSM source data.

A public `parse_overpass_response(payload)` helper lets tests load a
saved Overpass JSON without touching the network. The committed
tests/fixtures/robit_bata_osm.json (32 KB, 35 buildings) drives the
offline tests; one integration test queries Overpass live for central
Vaduz to exercise the full network path.

Implemented with stdlib only (urllib + json + math) — no new dependency
on osmnx, geopandas, or shapely.
@rehsani rehsani merged commit 3b73526 into main May 4, 2026
1 check passed
@rehsani rehsani deleted the step-3d-osm branch May 4, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant