6

I want to download a list of all countries on this planet from OSM. Also, for selected countries, I would like to have states and cities.

How can this easily be achieved? There must be an easier way that to download the whole planet and iterate through all nodes, ways and relation, checking for each whether it maches my criteria, I hope...

  • For major world cities metro.teczno.com – Mapperz Mar 29 '14 at 22:32
  • Thanks, but that's not quite what I want. I don't need a few specific individual cities. Rather, I'd like to have the whole world, but not in detail. For a specific city, I just want to know that it exists, what its name is, where on earth it is, and in which country. I don't need neighborhoods, streets POIs etc. – Michael Junk Apr 2 '14 at 13:42
4

Overpass API allows you to download only selected objects. For country borders, admin_level=2 should return the information you want:

<osm-script>
  <query type="relation">
    <has-kv k="admin_level" v="2"/>
  </query>
  <print mode="meta"/>
</osm-script>

This returns 302 border relations without all coordinates.

States and cities have higher admin levels according to the local administrative hierarchy.


Alternatively, you can query for nodes with place=country:

<osm-script>
  <query type="node">
    <has-kv k="place" v="country"/>
  </query>
  <print mode="meta"/>
</osm-script>

This returns 226 countries represented by a single point in the middle, including the coordinates.

  • Thanks! That seems to be a good resource. Unfortunately overpass-turbo.eu consistentenly times out. Any ideas? – Michael Junk Apr 2 '14 at 13:54
  • Try to load the relation without the border coordinates. Most countries have a lable point with place=country as you can see in my extended answer. – AndreJ Apr 2 '14 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.