Skip to content

Instantly share code, notes, and snippets.

@phaer
Created April 14, 2016 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phaer/abe53308659a2f9c0802d33251a4e257 to your computer and use it in GitHub Desktop.
Save phaer/abe53308659a2f9c0802d33251a4e257 to your computer and use it in GitHub Desktop.
Get RBL number for viennese public transport stops around a given location
/*
This has been generated by the overpass-turbo wizard.
The original search was:
“(railway=station or railway=tram_stop or highway=bus_stop) around Semperdepot”
*/
[out:json][timeout:25];
// adjust the search radius (in meters) here
{{radius=600}}
// gather results
(
// query part for: “railway=station”
node["railway"="station"](around:{{radius}},{{geocodeCoords:Semperdepot}});
way["railway"="station"](around:{{radius}},{{geocodeCoords:Semperdepot}});
relation["railway"="station"](around:{{radius}},{{geocodeCoords:Semperdepot}});
// query part for: “railway=tram_stop”
node["railway"="tram_stop"](around:{{radius}},{{geocodeCoords:Semperdepot}});
way["railway"="tram_stop"](around:{{radius}},{{geocodeCoords:Semperdepot}});
relation["railway"="tram_stop"](around:{{radius}},{{geocodeCoords:Semperdepot}});
// query part for: “highway=bus_stop”
node["highway"="bus_stop"](around:{{radius}},{{geocodeCoords:Semperdepot}});
way["highway"="bus_stop"](around:{{radius}},{{geocodeCoords:Semperdepot}});
relation["highway"="bus_stop"](around:{{radius}},{{geocodeCoords:Semperdepot}});
);
// print results
out body;
>;
out skel qt;
from collections import defaultdict
import json
import csv
# save the result of a query like http://overpass-turbo.eu/s/fDI to 'stations.geojson'
# wget https://data.wien.gv.at/csv/wienerlinien-ogd-{linien,haltestellen,steige}.csv
read_csv = lambda f: csv.DictReader(f, delimiter=';')
if __name__ == '__main__':
with open('wienerlinien-ogd-linien.csv') as line_file, \
open('wienerlinien-ogd-haltestellen.csv') as station_file, \
open('wienerlinien-ogd-steige.csv') as platform_file, \
open('stations.geojson') as osm_file:
osm = json.load(osm_file)
wanted_stations = {feature['properties']['name'] for feature in osm['features']}
lines_by_id = {line['LINIEN_ID']: line['BEZEICHNUNG']
for line in read_csv(line_file)}
stations_by_id = {station['HALTESTELLEN_ID']: station['NAME']
for station in read_csv(station_file)}
stations = defaultdict(list)
for platform in read_csv(platform_file):
name = stations_by_id[platform['FK_HALTESTELLEN_ID']]
if name not in wanted_stations:
continue
stations[name].append({
'rbl': platform['RBL_NUMMER'],
'line': lines_by_id[platform['FK_LINIEN_ID']],
'dir': platform['RICHTUNG']})
print(json.dumps(stations))
# print(set(wanted_stations) - set(stations.keys()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment