towerops/priv/repo/migrations/20260506205000_create_coverage_buildings.exs
Graham McIntire f77c493fa3 feat(lidar): nationwide USGS NED fallback (the actual code)
Earlier commit a9aa8bf9 had the message but only the test tweak made
it through pre-commit stashing. This is the implementation:

- lib/towerops/lidar/sources/usgs_ned.ex
- lib/towerops/lidar.ex (mosaic_from_ned + get_elevation_from_ned
  fallback paths)
- lib/towerops/coverages/building.ex + migration scaffolding
- lib/towerops/workers/coverage_worker.ex error message
- test_helper.exs and the lidar test changes
2026-05-06 16:21:50 -05:00

40 lines
1.4 KiB
Elixir

defmodule Towerops.Repo.Migrations.CreateCoverageBuildings do
use Ecto.Migration
def change do
create table(:coverage_buildings, primary_key: false) do
add :id, :bigserial, primary_key: true
# Provider key — lets us mix sources later (Microsoft, OpenStreetMap,
# custom user uploads) without cross-contaminating queries.
add :source, :string, null: false, default: "ms_global_ml"
# WGS84 polygon. PostGIS extension is enabled by an earlier migration.
add :geom, :"geometry(POLYGON, 4326)", null: false
# Top-of-roof height above ground in metres. May be NULL when the
# source has no height data — the propagation pipeline falls back
# to a single-storey default.
add :height_m, :float
add :derived_height, :boolean, null: false, default: false
# External provider IDs we keep so a re-import is idempotent.
add :ms_footprint_id, :string
timestamps(type: :utc_datetime, updated_at: false)
end
# Spatial GiST index for the bounding-box intersect queries the
# coverage worker runs when it builds the per-tile DSM.
execute(
"CREATE INDEX coverage_buildings_geom_idx ON coverage_buildings USING GIST (geom)",
"DROP INDEX coverage_buildings_geom_idx"
)
create index(:coverage_buildings, [:source])
create unique_index(:coverage_buildings, [:source, :ms_footprint_id],
where: "ms_footprint_id IS NOT NULL"
)
end
end