I have exported OpenStreetMap (OSM) data of a city to my local postgresql db using osm2pgsql.

I would like to add the General Transit Feed Specification (GTFS) routes information (say bus routes) into planet_osm_roads table as tags - say route_id(s) and agency_id(s).

All the open source GTFS tools seem to use gtfs stops as nodes. Opentripplanner, for example, does use osm street data while building the graph nodes to better understand the stops but the osm part stops right there.

I could probably iterate over all the routes, enlist all the stops in each of the trips and use routing library like PgRouting to determine the path (i.e street names) between those stops.

This seems to be a decent way, but there is no guarantee that the paths are indeed that used by the bus routes.

Any suggestions how should I be approaching this problem?

  • I'm not that experienced with PT, so can you please say in 2 sentences what you want to do, where it fails and what you tried to solve it?
    – Mapper
    Jun 22, 2014 at 8:29
  • @Mapper - I am not sure what you mean by PT (planning trips?) but simply put - see title, I would like to get the path (list of street names) of any GTFS route. Jun 22, 2014 at 9:34
  • PT=public transport You might want to try overpass api PT example: overpass-api.de
    – Mapper
    Jun 22, 2014 at 20:04
  • @Mapper - I think I found a simpler way to do it. GTFS data has a file called shapes.txt which essentially contains lat,lon for drawing public transit lines on a map. I think the best way is to just query the planet_osm_roads table with the road containing or closest to each of the points. I shall update my answer if I can successfully implement what I am thinking. Jun 23, 2014 at 16:03

2 Answers 2


You could load into opentripplanner, and then query the REST interface directly with a trip query and will return the shape (i.e a polyline of points) that you want. I that's what you want.


Till I find a better way, I am taking the following approach which does solve my cause.

Note - We are concerned with shapes.txt, trips.txt and routes.txt from the GTFS data.

To add route_id tag to the streets that lie along a particular route:

  1. Use trips.txt to collect shape_ids for the route_id.
  2. Each shape_id in shapes.txt gives a list of points - which could be used to get street names from the postgre table. Check closest line to a point
  3. Collect unique street names/ids per route_id - which could then be used to modify the tags in their corresponding rows in the table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.