2

I want to retrieve all the bus routes (as a collection of lines) from openstreetmap for a given city.

I'm currently using the overpy module (v0.4) to access the Overpass API and this query:

QUERY = """
[out:json];
area[name="%(city)s"]->.a;
(
  node["route"="%(type)s"](area.a);
  way["route"="%(type)s"](area.a);
  relation["route"="%(type)s"](area.a);
);
out body;
>;
out skel;
"""

where city is the city i'm interested in, and type could either be bus or tram.

The problem is, this does not work often :( If I'm looking for the bus routes for a very well known city like Chicago it returns an empty set, while other times the result set is partial (like for Philadelphia for example); very rarely it is able to correctly select the city and grab all the routes.

If I use the same query (without the area selector) in http://overpass-turbo.eu/ when focused on Chicago it is able to return the routes as expected; so I suspect there's something wrong with the way I'm using area

Do you have any idea how can I achieve this?

  • Maybe just try a bounding box search for whatever you consider the city extent to be? – BradHards Jun 29 '17 at 3:55
  • Your query works fine for Chicago: overpass-turbo.eu/s/q46. However you can omit searching for nodes and ways, they are never tagged with route=bus (otherwise it is a tagging error). Maybe you are hitting some quota? For example too many parallel requests. Check the HTTP status code – scai Jun 29 '17 at 7:30
  • @BradHards i want to do this programmatically, so i dont want to have to find the bbox of that city by hand: do you know of a way to do that automatically? – Sandro Tosi Jun 29 '17 at 13:46
  • @scai yes i know that query works when entered in overpass-turbo (i even mentioned it in the OP, but thanks for checking it) i dont think there's any quota issue here, as running it for NYC it will return something – Sandro Tosi Jun 29 '17 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.