2022-04-30 18:31:32 +00:00
|
|
|
CREATE OR REPLACE FUNCTION layer_obs_events(bbox geometry, zoom_level int, user_id integer, min_time timestamp, max_time timestamp)
|
2022-05-02 20:00:17 +00:00
|
|
|
RETURNS TABLE(event_id bigint, geometry geometry, distance_overtaker float, distance_stationary float, direction int, course float, speed float, zone zone_type, way_id bigint) AS $$
|
2021-10-10 10:32:28 +00:00
|
|
|
|
|
|
|
SELECT
|
2022-04-30 18:31:32 +00:00
|
|
|
overtaking_event.id::bigint as event_id,
|
2021-10-10 10:32:28 +00:00
|
|
|
ST_Transform(overtaking_event.geometry, 3857) as geometry,
|
|
|
|
distance_overtaker,
|
|
|
|
distance_stationary,
|
|
|
|
(case when direction_reversed then -1 else 1 end)::int as direction,
|
|
|
|
course,
|
|
|
|
speed,
|
2022-05-05 21:16:38 +00:00
|
|
|
CASE WHEN road.zone IS NULL THEN 'urban' else road.zone END as zone,
|
|
|
|
overtaking_event.way_id::bigint as way_id
|
2021-10-10 10:32:28 +00:00
|
|
|
FROM overtaking_event
|
2022-04-30 18:31:32 +00:00
|
|
|
FULL OUTER JOIN road ON road.way_id = overtaking_event.way_id
|
|
|
|
JOIN track on track.id = overtaking_event.track_id
|
|
|
|
WHERE ST_Transform(overtaking_event.geometry, 3857) && bbox
|
|
|
|
AND (user_id is NULL OR user_id = track.author_id)
|
|
|
|
AND time BETWEEN COALESCE(min_time, '1900-01-01'::timestamp) AND COALESCE(max_time, '2100-01-01'::timestamp);
|
2021-10-10 10:32:28 +00:00
|
|
|
|
|
|
|
$$ LANGUAGE SQL IMMUTABLE;
|