This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Overpass query optimisation

0

I am trying to write a query that will return all pubs and bars around a certain point. I'm having issues with the results that are ways. At the moment I am getting all the nodes for the way and then using some post processing to match up the first node of the way to the node lat/long data. Obviously, this is largely inefficient. This is the query I'm currently using. Many thanks.

[out:json]; (node[amenity=pub](around:5000,51.5152117,-0.144044); foreach(out;) way[amenity=pub](around:5000,51.5152117,-0.144044); foreach( out; node(w); out; ); node[amenity=bar](around:5000,51.5152117,-0.144044); foreach(out;) way[amenity=bar](around:5000,51.5152117,-0.144044); foreach( out; node(w); out;);); (._;%3E;)

asked 29 Sep '18, 23:26

adam__'s gravatar image

adam__
16113
accept rate: 0%


One Answer:

4

Each way lists it's member nodes, so in your post processing you can build a mapping of node ids to nodes and use that to retrieve a way node, you don't need to order the output. So a query like http://overpass-turbo.eu/s/Cne should work.

[out:json];
(node[amenity=pub](around:5000,51.5152117,-0.144044);
way[amenity=pub](around:5000,51.5152117,-0.144044);
node[amenity=bar](around:5000,51.5152117,-0.144044);
way[amenity=bar](around:5000,51.5152117,-0.144044);
);
(._;>;);
out;

You might also be interested in out center; which converts ways to a node at the center of the bounding box of the way (or relation).

answered 30 Sep '18, 04:30

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

out center is exactly what I'm after. My final query is http://overpass-turbo.eu/s/Cns since I don't need individual lat/lon of the ways nodes

(30 Sep '18, 12:10) adam__

Source code available on GitHub .