Skip to content

Commit

Permalink
update station importance views with ID column
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddewie committed Aug 1, 2024
1 parent ebc5be5 commit 35bf789
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions import/sql/get_station_importance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ CREATE OR REPLACE VIEW platforms_and_their_routes_clustered AS

-- Join clustered stop positions with station nodes
CREATE OR REPLACE VIEW station_nodes_stop_positions_rel_count AS
SELECT s.osm_id, s.name AS name, s.station as station, s.railway_ref as railway_ref, s.railway AS railway, sprc.route_ids AS route_ids, s.name_tags as name_tags, s.way AS way
SELECT s.id as id, s.osm_id, s.name AS name, s.station as station, s.railway_ref as railway_ref, s.railway AS railway, sprc.route_ids AS route_ids, s.name_tags as name_tags, s.way AS way
FROM stations AS s
LEFT OUTER JOIN stop_positions_and_their_routes_clustered AS sprc
ON (sprc.stop_name = s.name AND ST_DWithin(s.way, sprc.geom, 400))
WHERE s.railway IN ('station', 'halt', 'tram_stop', 'service_station', 'yard', 'junction', 'spur_junction', 'crossover', 'site');

-- Join clustered platforms with station nodes
CREATE OR REPLACE VIEW station_nodes_platforms_rel_count AS
SELECT s.osm_id AS osm_id, s.name AS name, s.station as station, s.railway_ref as railway_ref, s.railway AS railway, sprc.route_ids AS route_ids, s.name_tags as name_tags, s.way AS way
SELECT s.id as id, s.osm_id AS osm_id, s.name AS name, s.station as station, s.railway_ref as railway_ref, s.railway AS railway, sprc.route_ids AS route_ids, s.name_tags as name_tags, s.way AS way
FROM stations AS s
JOIN platforms_and_their_routes_clustered AS sprc
ON (ST_DWithin(s.way, sprc.geom, 60))
Expand All @@ -60,19 +60,19 @@ CREATE OR REPLACE VIEW station_nodes_platforms_rel_count AS
-- needs about 3 to 4 minutes for whole Germany
-- or about 20 to 30 minutes for the whole planet
CREATE MATERIALIZED VIEW IF NOT EXISTS stations_with_route_counts AS
SELECT DISTINCT ON (osm_id, name, station, railway_ref, railway) osm_id, name, station, railway_ref, railway, route_count, name_tags, way
SELECT DISTINCT ON (osm_id, name, station, railway_ref, railway) id, osm_id, name, station, railway_ref, railway, route_count, name_tags, way
FROM (
SELECT osm_id, name, station, railway_ref, railway, ARRAY_LENGTH(ARRAY_AGG(DISTINCT route_id), 1) AS route_count, name_tags, way
SELECT id, osm_id, name, station, railway_ref, railway, ARRAY_LENGTH(ARRAY_AGG(DISTINCT route_id), 1) AS route_count, name_tags, way
FROM (
SELECT osm_id, name, station, railway_ref, railway, UNNEST(route_ids) AS route_id, name_tags, way
SELECT id, osm_id, name, station, railway_ref, railway, UNNEST(route_ids) AS route_id, name_tags, way
FROM station_nodes_stop_positions_rel_count
UNION ALL
SELECT osm_id, name, station, railway_ref, railway, UNNEST(route_ids) AS route_id, name_tags, way
SELECT id, osm_id, name, station, railway_ref, railway, UNNEST(route_ids) AS route_id, name_tags, way
FROM station_nodes_platforms_rel_count
) AS a
GROUP BY osm_id, name, station, railway_ref, railway, way, name_tags
GROUP BY id, osm_id, name, station, railway_ref, railway, way, name_tags
UNION ALL
SELECT osm_id, name, station, railway_ref, railway, 0 AS route_count, name_tags, way
SELECT id, osm_id, name, station, railway_ref, railway, 0 AS route_count, name_tags, way
FROM stations
WHERE railway IN ('station', 'halt', 'tram_stop', 'service_station', 'yard', 'junction', 'spur_junction', 'crossover', 'site')
) AS facilities
Expand Down

0 comments on commit 35bf789

Please sign in to comment.