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

Get city nodes within a country using Overpass API

3
1

Is it possible to get all city nodes within a country using the overpass api? Preferably using relations rather than a bounding box.

If I have to do this using a bounding box, is it possible to get a country bounding box through the overpass api too?

https://help.openstreetmap.org/questions/13872/how-to-find-list-of-cities-in-a-state-with-overpass-osm-api shows how to do this within a bounding box. I would rather do this using relations to get a more accurate list of cities (especially since overpass doesn't appear to return a bounding box for the country node to start with)

asked 14 Jan '13, 04:32

rjmackay's gravatar image

rjmackay
61113
accept rate: 0%


One Answer:

10

The following overpass query returns the list of all cities in Belgium:

area[name="België - Belgique - Belgien"];(node[place="city"](area););out;

You can replace the name with any country (or other administrative level) you want. Areas are explained here: https://wiki.openstreetmap.org/wiki/Overpass_API/Areas

answered 14 Jan '13, 04:47

escada's gravatar image

escada
19.0k16166302
accept rate: 21%

edited 14 Jan '13, 04:49

1

Brilliant, thanks! Areas are what I need and what I'd missed in the docs.

(14 Jan '13, 04:55) rjmackay

Source code available on GitHub .