I constructed a python query to look for all the bus routes passing by a given box. However, I need to speed up the query as much as possible. I only need the lat/lon coordinates of each node representing the bus stops and the name of the routes that they belong to. My current code:

import requests

overpass_url = "http://overpass-api.de/api/interpreter"

bbox = [48.87542724909715, 2.1707384550740683, 48.88884184835508, 2.1821696229817267]
bbox_str = '('+str(bbox)[1:-1]+')'

overpass_query = '''
[out:json];
(
relation'''+bbox_str+'''['route'='bus'];
);
out body;
>;
out skel;
'''

response = requests.get(overpass_url, params={'data': overpass_query})
data = response.json()

asked 16 Feb, 17:51

fragodec's gravatar image

fragodec
16225
accept rate: 0%

edited 16 Feb, 17:53


I don't know if it is more efficient and/or faster but you could search for every bus stop in a given bounding box and then recurse back to the relations that have that stop as member:

[out:json][timeout:25];

// query part for: “highway=bus_stop”
node["highway"="bus_stop"]({{bbox}})->.stops;

foreach.stops ->.s(

  //get the route (stop must be a member!)
  rel(bn.s)[type=route]->.r;

  //produce output
  make stop name = s.u(t["name"]),
  lat = s.u(lat()), 
  lon = s.u(lon()),
  lines = r.set(t["ref"]);

  //print
  out meta;     
);
permanent link

answered 20 Feb, 21:26

MarcoR's gravatar image

MarcoR
6123718
accept rate: 27%

Thank you for your answer. This works fine but unfortunately it is slower than my code (with the examples I tried).

(22 Feb, 11:17) fragodec
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×139
×73
×10

question asked: 16 Feb, 17:51

question was seen: 360 times

last updated: 22 Feb, 11:18

powered by OSQA