Retrieve public transport information for a city


I am trying to analyse the public transport infrastructure of cities (in Germany), so that means I am looking for all bus, tram and subway lines (=relations) within a city.

To get the strength of the public transport network, I also need to know how often this bus/tram/subway travels that route per week to get a reasonable estimate (does not need to be 100% precise).

I have been thinking for a while on how to achieve this and my best idea right now is to (somehow) fetch all the relations from OSM data and cross-reference the line’s “ref” with timetable data and hope it works out.

I found this old post here for getting OSM Data ( Retrieve all bus routes for a given city - OSM Help ) but it recommends not using the API for a large data retrieval and instead download the data and analyse it with another tool that I am not familiar with.

This leaves me with some questions:
a) How do I query all relations that I need?
b) How do I limit the query to (roughly) the city/municipality that I am analysing? (Just a radius from city centre can be way off)
c) Does anyone have an alternate suggestion for me to achieve this analysis more easily? I just need a good indicator for public transport network strength (only looking at local/short-distance travel) and the total amount of km travelled by public transport vehicles in a week seems like a decent estimation.

Any ideas? :slight_smile:

Have a look at PTNA , it uses the overpass api.
You’re from DE? Click on the german flag for the results and on a link in the “Konfiguration” column. You’ll see the overpass query. Just change the search area.

You need departure times? GTFS is your friend. PTNA shows selected GTFS feeds in an aggregated way. As departure times are not of great interest in OSM, PTNA’s aggregation is not very helpful.
Try to find GTFS sources of your area of interest and create your needed SQL queries for the data.

As suggested by the answer to the question you linked, the edit API is unsuitable, but the Overpass API will probably be ok for city level stuff.

If you have JOSM running in “expert” mode there are some pre-saved Overpass download scripts for various types of public transport available in the download window. A bit of messing around with them to use a geocoded search area (which Overpass turbo supports) rather than a bounding box should give you what you want as long as mappers have added the relevant boundaries and routes into OSM.

Btw. Someone from the ADFC in Munich did similar things to evaluate the frequency of buses stoping at a specific stop.

  • more often than every 20 minutes? cycleways should not be constructed such that the cyclists might collide with passengers leaving/entering the buses.

that means I am looking for all bus, tram and subway lines (=relations) within a city.

for a more complete picture you should also look at trains and light rail which often are useful for travelling inside of bigger towns and cities.
The relations in OpenStreetMap are not just lines, there is one relation for every variation of a line, often also separated by direction (ideally, in reality it may not be complete everywhere)

To get an idea how often stops are served, you will need schedule information. The Germen DELFI e.V. publishes this as CC-BY licensed GTFS dataset. Although it has some quality issues and you’ll need to prepare the data for efficient querying, e.g. with a tool like gtfs-via-postgres, it will IMHO be more suited for your use case than OSM data.