diff --git a/pipeline/transform/models/marts/dim_location.sql b/pipeline/transform/models/marts/dim_location.sql index fedc066..3f7d4de 100644 --- a/pipeline/transform/models/marts/dim_location.sql +++ b/pipeline/transform/models/marts/dim_location.sql @@ -1,5 +1,6 @@ -- Mart: School location dimension — one row per URN, PostGIS-enabled --- The geom column is populated by a post-hook or the geocode script. +-- Geometry derived from GIAS easting/northing (British National Grid → WGS84). +-- For schools missing easting/northing, the geocode script backfills via Postcodes.io. select s.urn, @@ -13,7 +14,12 @@ select s.parliamentary_constituency, s.urban_rural, s.easting, - s.northing + s.northing, + case + when s.easting is not null and s.northing is not null + then ST_Transform(ST_SetSRID(ST_MakePoint(s.easting, s.northing), 27700), 4326) + else null + end as geom from {{ ref('stg_gias_establishments') }} s where s.status = 'Open' and s.postcode is not null