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) But I don't know how I can fetch this. Could be something like? For example nearby cities in Madrid in 10 km:
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 |
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:
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":
Now that you have the central node, you can use the around command to query everything around Madrid, like this:
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.
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). answered 29 Feb '16, 13:09 Sanderd17 |