0

I would like know how I can get in a json output format the cities around a city.

For example:

Cities around "London" in 10 km.

I read about "around" http://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Relative_to_other_elements_.28around.29

And querying about interest poins nearby (like cafe or bar)

http://stackoverflow.com/questions/16442663/how-to-get-point-of-interest-near-my-point-using-overpass-api

But I don't know how I can fetch this.

Could be something like? For example nearby cities in Madrid in 10 km:

[out:json];node(name="Madrid")[around:10000];out;

I am trying to achieve this for a PHP script, so I plan use a curl request with the OverPass API.

asked 28 Feb '16, 00:09

shakaran's gravatar image

shakaran
21112
accept rate: 0%


One Answer:
5

When working with Overpass API, it's good to use Overpass turbo (a web-IDE written around Overpass API) to test your queries.

Overpass turbo will also give you error messages

Now, for the actual question. First you need to create the input set of the "around" command (or you need to know the coordinates you want to query around). That depends a bit on the place you want to query. Some names are used for a lot of different places, so finding a good selector for it is crucial

In the example of Madrid, you will see that there are 22 places called Madrid, while there's only one city called Madrid. Compare the following two queries in Overpass Turbo:

node["place"]["name"="Madrid"];
out;

node["place"="city"]["name"="Madrid"];
out;

When you have found a good selector (based on tags or any other criterium Overpass can handle), you need to save that point into a set, let's call the set "center":

node["place"="city"]["name"="Madrid"]->.center;

Now that you have the central node, you can use the around command to query everything around Madrid, like this:

node["place"="city"]["name"="Madrid"]->.center;
node(around.center:10000);

But this will query every single object in that area (and will probably be too big for your browser to handle). So then you need to filter the results further with other filters. F.e. related to your query, all places near Madrid (cities are usually further apart than 10km, so that wouldn't yield any results).

So the full query looks like this.

node["place"="city"]["name"="Madrid"]->.center;
node(around.center:10000)["place"];
out;

And when you execute the query, you'll see the results: http://overpass-turbo.eu/s/eHb

When you're finished, you can use one of the export functions of Overpass Turbo to get it formatted as a nice URL (without useless whitespace and with fully escaped special characters).

permanent link

answered 29 Feb '16, 13:09

Sanderd17's gravatar image

Sanderd17
1.1k51637
accept rate: 32%

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:

×22
×12
×9

question asked: 28 Feb '16, 00:09

question was seen: 4,526 times

last updated: 29 Feb '16, 13:09

powered by OSQA