obs-portal/tile-generator/layers/obs_regions/layer.sql

27 lines
814 B
MySQL
Raw Normal View History

DROP FUNCTION IF EXISTS layer_obs_regions(geometry, int);
CREATE OR REPLACE FUNCTION layer_obs_regions(bbox geometry, zoom_level int)
RETURNS TABLE(
2023-03-31 19:06:59 +00:00
region_id int,
geometry geometry,
name text,
overtaking_event_count int
) AS $$
SELECT
2023-03-31 19:06:59 +00:00
-- region.id as region_id,
NULL::int as region_id,
-- ST_SimplifyPreserveTopology(region.geometry, ZRes(zoom_level + 2)) as geometry,
region.geometry as geometry,
region.name as name,
count(overtaking_event.id)::int as overtaking_event_count
FROM region
2023-04-01 14:44:47 +00:00
LEFT OUTER JOIN overtaking_event on ST_Within(overtaking_event.geometry, region.geometry)
WHERE
2023-03-31 19:06:59 +00:00
zoom_level >= 3 AND
zoom_level <= 12 AND
region.geometry && bbox
2023-03-31 19:06:59 +00:00
GROUP BY region.id, region.name, region.geometry
$$ LANGUAGE SQL IMMUTABLE;