List of countries and their regions


New to the forum!

I am working on a project where I have biking routes from all over the world (I only have the coordinates).
I would like to make a nice catalog where I group these biking routes by country and region, so I thought of using data from OSM to achieve this.

So far my idea is to use Overpass data, to find all relations with tags [“admin_level”=“2”] and [“boundary”=“administrative”] , like this: overpass turbo . The second step would be to iterate over them ant obtain the relations with the lower level and then recursively continue until I am done.

The problem I ran into is that this works for some countries (Australia), but for others like Denmark (overpass turbo) or Germany I get no results on the second query.

What am I doing wrong? Also, am I reinventing the wheel? I have found other resources such as GitHub - nzzdev/osm-regions: Extract region geometries (ISO 3166 countries and subdivisions) from OpenStreetMap in order to create a region dataset compatible with OpenMapTiles., but they don’t use all admin_levels available.

Thanks in advance,

PS: I have a few more examples, but I could only add 3 links.

  1. Recursing is inefficient, and should be avoided. This also processes many sections redundantly. You can simply dl every route=bicycle to organize them yourself locally.
  2. I don’t understand the question fully. You can refer to Tag:boundary=administrative - OpenStreetMap Wiki for what each country uses first. They can be inspected in as a whole. Again, it’s not the most useful to recurse the admin_level= . Go get every rel[boundary=administrative] directly.

Thanks for your quick reply

I understand the confusion. I agree that to get the admin levels of each bike route I can just run the route (or the last point of the route) on overpass turbo.

What I am trying to achieve is to get a list of all the countries and their lower admin levels, and so far I am using the queries I posted above.

Also, when I said recursively I meant on python. The idea is to:

  1. get a list of all countries
  2. for each country get all levels 3 (if they exist) and then for each result try with a lower level
  3. the expected result is to get a tree with all countries and all their lower admin levels
  4. in the second query I posted, I use “parent”, because it is very important to know the connection between the different relations

I hope this is more clear.

Best, Alvaro