Skip to content

Commit

Permalink
Improve grouped stations and tile rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddewie committed Dec 16, 2024
1 parent bee9db1 commit b6cb2b8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 57 deletions.
61 changes: 34 additions & 27 deletions import/sql/get_station_importance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,45 @@ CREATE OR REPLACE VIEW station_nodes_platforms_rel_count AS
-- or about 20 to 30 minutes for the whole planet
CREATE MATERIALIZED VIEW IF NOT EXISTS stations_with_route_counts AS
SELECT
MIN(id) as id,
MIN(osm_id) as osm_id,
name,
station,
railway_ref,
railway,
MAX(route_count) as route_count,
hstore(string_agg(nullif(name_tags::text, ''), ',')) as name_tags,
ST_RemoveRepeatedPoints(ST_Collect(way)) as way
*,
ST_Centroid(way) as center,
ST_Buffer(ST_ConvexHull(way), 50) as buffered,
ST_NumGeometries(way) as count
FROM (
SELECT
*,
ST_ClusterDBSCAN(way, 400, 1) OVER (PARTITION BY name, station, railway_ref, railway) AS cluster_id
MIN(id) as id,
MIN(osm_id) as osm_id,
name,
station,
railway_ref,
railway,
MAX(route_count) as route_count,
hstore(string_agg(nullif(name_tags::text, ''), ',')) as name_tags,
ST_RemoveRepeatedPoints(ST_Collect(way)) as way
FROM (
SELECT MIN(id) as id, MIN(osm_id) as osm_id, name, station, railway_ref, railway, ARRAY_LENGTH(ARRAY_AGG(DISTINCT route_id), 1) AS route_count, name_tags, way
SELECT
*,
ST_ClusterDBSCAN(way, 400, 1) OVER (PARTITION BY name, station, railway_ref, railway) AS cluster_id
FROM (
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
SELECT MIN(id) as id, MIN(osm_id) as osm_id, name, station, railway_ref, railway, ARRAY_LENGTH(ARRAY_AGG(DISTINCT route_id), 1) AS route_count, name_tags, way
FROM (
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 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 name, station, railway_ref, railway, way, name_tags
UNION ALL
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 name, station, railway_ref, railway, way, name_tags
UNION ALL
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 grouped_facilities
) AS facilities
GROUP BY name, station, railway_ref, railway, cluster_id
-- ORDER BY is required to ensure that the larger route_count is used.
ORDER BY name, station, railway_ref, railway, route_count DESC;
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 grouped_facilities
) AS facilities
GROUP BY name, station, railway_ref, railway, cluster_id
-- ORDER BY is required to ensure that the larger route_count is used.
ORDER BY name, station, railway_ref, railway, route_count DESC
) as source_facilities;

CREATE INDEX IF NOT EXISTS stations_with_route_counts_geom_index
ON stations_with_route_counts
Expand Down
12 changes: 6 additions & 6 deletions import/sql/tile_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ CREATE OR REPLACE VIEW standard_railway_text_stations_low AS
SELECT
id,
osm_id,
ST_Centroid(way) as way,
center as way,
railway_ref as label
FROM stations_with_route_counts
WHERE
Expand All @@ -153,7 +153,7 @@ CREATE OR REPLACE VIEW standard_railway_text_stations_med AS
SELECT
id,
osm_id,
ST_Centroid(way) as way,
center as way,
railway_ref as label
FROM stations_with_route_counts
WHERE
Expand All @@ -166,7 +166,7 @@ CREATE OR REPLACE VIEW standard_railway_text_stations AS
SELECT
id,
osm_id,
way,
center as way,
railway,
station,
railway_ref as label,
Expand All @@ -191,13 +191,13 @@ CREATE OR REPLACE VIEW standard_railway_text_stations AS
SELECT
id,
osm_id,
ST_Centroid(way) as way,
center,
railway,
route_count,
station,
railway_ref,
name,
ST_NumGeometries(way) as count
count
FROM stations_with_route_counts
WHERE railway IN ('station', 'halt', 'service_station', 'yard', 'junction', 'spur_junction', 'crossover', 'site', 'tram_stop')
AND name IS NOT NULL
Expand All @@ -217,7 +217,7 @@ CREATE OR REPLACE VIEW standard_railway_grouped_stations AS
SELECT
id,
osm_id,
ST_Buffer(ST_ConvexHull(way), 50) as way,
buffered as way,
railway,
station,
railway_ref,
Expand Down
25 changes: 1 addition & 24 deletions proxy/js/styles.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,32 +1387,9 @@ const layers = Object.fromEntries(knownThemes.map(theme => [theme, {
{
id: 'railway_grouped_stations',
type: 'fill',
minzoom: 8,
minzoom: 15,
source: 'openrailwaymap_standard',
'source-layer': 'standard_railway_grouped_stations',
filter: ['step', ['zoom'],
['all',
['==', ['get', 'railway'], 'station'],
['!=', ['get', 'station'], 'light_rail'],
['!=', ['get', 'station'], 'subway'],
['!=', ['get', 'station'], 'funicular'],
],
9,
['all',
['any',
['==', ['get', 'railway'], 'station'],
['==', ['get', 'railway'], 'halt'],
],
['!=', ['get', 'station'], 'funicular'],
],
10,
['all',
['!=', ['get', 'railway'], 'tram_stop'],
['!=', ['get', 'station'], 'funicular'],
],
13,
['!=', ['get', 'station'], 'funicular'],
],
paint: {
'fill-color': ['case',
['==', ['get', 'railway'], 'tram_stop'], colors[theme].styles.standard.tram,
Expand Down

0 comments on commit b6cb2b8

Please sign in to comment.