File size: 984 Bytes
c7c5661 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | -- BigQuery GIS proof: event point and optional distance from MAREA.
-- Use after Bronze has rows: event point from usgs_raw, MAREA stub from data/marea_route.json
-- or a single-row table. For Week 3, wrap in risk_proximity.sql with 200 km buffer.
--
-- Note: BigQuery uses ST_GEOGFROMTEXT (WKT format), not ST_GEOGFROMGEOJSON.
-- For GeoJSON files (e.g., data/marea_route.json), convert to WKT or use a Python
-- library (e.g., shapely) to convert before BigQuery insert.
-- Example: point from lat/lon
-- SELECT ST_GEOGPOINT(lon, lat) AS geography FROM bronze.usgs_raw LIMIT 1;
-- Example: distance (meters) from a test point to MAREA stub (Virginia Beach ≈ -75.98, 36.85)
WITH marea_stub AS (
SELECT ST_GEOGFROMTEXT('LINESTRING(-75.98 36.85, -2.99 43.38)') AS route_geom
),
test_point AS (
SELECT ST_GEOGPOINT(-76.0, 37.0) AS pt -- near Virginia Beach
)
SELECT
ST_DISTANCE(t.pt, m.route_geom) / 1000 AS distance_km
FROM test_point t, marea_stub m;
|