3

I'm a developer that's trying to build a django application and trying to incorporate the Overpass API to it. I'm new to the API and OpenStreetMap (and GIS in general), so I thought I would start off by getting a list of all of the countries and build from that.

However I've searched online and nowhere does it mention how to do this with the API, can someone show what query does this?

3
  • 2
    If you incorporate this in your app, don't forget to send a meaningful User Agent along with your HTTP request (not just the default one as set by your framework) and - as the list of countries does not change every 2 minutes - preferably use some local caching! According to the usage policy, there's a max of 10'000 requests per day.
    – mmd
    Commented Feb 3, 2017 at 8:26
  • I'm not sure what you mean by user agent. Commented Feb 3, 2017 at 8:50
  • 3
    See en.wikipedia.org/wiki/User_Agent
    – mmd
    Commented Feb 3, 2017 at 8:59

2 Answers 2

3

The Overpass Turbo query for a list of all countries is

[out:csv("name:en")];relation["admin_level"="2"];out;

You can get it from the command line with

 overpass-api.de/api/interpreter?data=%5Bout%3Acsv%28%22name%3Aen%22%29%5D%3Brelation%5B%22admin_level%22%3D%222%22%5D%3Bout%3B%0A
1
  • 1
    The results of this query look a bit strange, as it includes empty lines and things like "Austria — Czech Republic". I'd recommend to include the ISO3166-1 tags as well: [out:csv("name:en")]; relation["admin_level"="2"]["ISO3166-1"~"^..$"];out;
    – mmd
    Commented Feb 4, 2017 at 12:36
1

The Overpass Turbo query for a list of all countries is

[out:csv("name:en")];relation["admin_level"="2"][boundary=administrative][type!=multilinestring];out;

See http://overpass-turbo.eu/s/uiX for results.

Note added boundary=administrative compared to accepted result - it removes some unwanted results like high-level religious boundaries ( https://www.openstreetmap.org/relation/7826647 is an example)

type!=multilinestring removes boundary sections (see https://wiki.openstreetmap.org/wiki/France_boundary_pyramidal_construction why not adding it lists countries such as "France - Italy")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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