I have the following WITH SQL Query which does select a set of filling stations along a route within the distance of 1000m. In the SQL statement I fetch 1 Point from the station and search the closest point in my routing network, but I want to do this for all stations from the WITH Query
WITH stations AS (SELECT id, geom FROM de_tt_stations AS s
WHERE ST_DWithin(
s.geom::geography,
(SELECT ST_LineMerge(ST_union(geom_way))::geography FROM route),
1000)
)
SELECT 1378549, destination
FROM (
SELECT id::integer AS destination
FROM de_2po_vertex ORDER BY geom_vertex <-> (
SELECT geom FROM stations LIMIT 1)
LIMIT 1)
AS foo
From the resulting list then I want to calculate the length of each route so that I can choose the closest filling station. Optimal output would look like
start | destination | station_id | length
---------------------------------------------------------
1378549 | de_2po_vertex.id | stations.id | pgr_dijkstra()
...