NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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%


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).

permanent link

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__

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:

×483
×85
×65

question asked: 29 Sep '18, 23:26

question was seen: 1,906 times

last updated: 30 Sep '18, 12:10

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum