2026-03-26 08:37:53 +00:00
|
|
|
-- Mart: School location dimension — one row per URN, PostGIS-enabled
|
2026-03-26 21:17:08 +00:00
|
|
|
-- Geometry derived from GIAS easting/northing (British National Grid → WGS84).
|
|
|
|
|
-- For schools missing easting/northing, the geocode script backfills via Postcodes.io.
|
2026-03-26 08:37:53 +00:00
|
|
|
|
|
|
|
|
select
|
|
|
|
|
s.urn,
|
|
|
|
|
s.address_line1,
|
|
|
|
|
s.address_line2,
|
|
|
|
|
s.town,
|
|
|
|
|
s.county,
|
|
|
|
|
s.postcode,
|
|
|
|
|
s.local_authority_code,
|
|
|
|
|
s.local_authority_name,
|
|
|
|
|
s.parliamentary_constituency,
|
|
|
|
|
s.urban_rural,
|
|
|
|
|
s.easting,
|
2026-03-26 21:17:08 +00:00
|
|
|
s.northing,
|
|
|
|
|
case
|
|
|
|
|
when s.easting is not null and s.northing is not null
|
2026-03-26 21:45:53 +00:00
|
|
|
then ST_Transform(ST_SetSRID(ST_MakePoint(s.easting::double precision, s.northing::double precision), 27700), 4326)
|
2026-03-26 21:17:08 +00:00
|
|
|
else null
|
2026-03-26 22:45:02 +00:00
|
|
|
end as geom,
|
|
|
|
|
case
|
|
|
|
|
when s.easting is not null and s.northing is not null
|
|
|
|
|
then ST_Y(ST_Transform(ST_SetSRID(ST_MakePoint(s.easting::double precision, s.northing::double precision), 27700), 4326))
|
|
|
|
|
else null
|
|
|
|
|
end as latitude,
|
|
|
|
|
case
|
|
|
|
|
when s.easting is not null and s.northing is not null
|
|
|
|
|
then ST_X(ST_Transform(ST_SetSRID(ST_MakePoint(s.easting::double precision, s.northing::double precision), 27700), 4326))
|
|
|
|
|
else null
|
|
|
|
|
end as longitude
|
2026-03-26 08:37:53 +00:00
|
|
|
from {{ ref('stg_gias_establishments') }} s
|
2026-08-20 21:46:28 +01:00
|
|
|
-- Must match dim_school's status and England filters exactly (the API
|
|
|
|
|
-- inner-joins the two).
|
2026-07-09 10:45:15 +01:00
|
|
|
where s.status_code in (1, 3)
|
2026-08-20 21:46:28 +01:00
|
|
|
-- coalesce, not a bare NOT IN: a null type code would make the predicate
|
|
|
|
|
-- null and drop the row silently. Unknown type is not grounds for exclusion.
|
|
|
|
|
and coalesce(s.school_type_code, -1) not in ({{ var('non_england_school_type_codes') | join(', ') }})
|
2026-08-20 22:54:24 +01:00
|
|
|
-- Welsh schools GIAS does not type as Welsh establishments (see vars).
|
|
|
|
|
and coalesce(s.local_authority_code, -1) not between {{ var('welsh_la_code_min') }} and {{ var('welsh_la_code_max') }}
|