How to access polygons for countries and subnational regions (e.g., states, autonomous communities)?

Hi everyone,

I’m developing a travel app for iOS (iPhone and iPad) where users can mark the countries, regions, or cities they’ve visited. I’m looking to include polygon shapes on a map to visually represent these areas.

I’ve seen that OpenStreetMap includes boundaries for countries, but I’d also like to access the next administrative level — such as states in the US, autonomous communities in Spain, provinces in Italy, etc.

What’s the best way to access this kind of data from OpenStreetMap?
• Is there a public GeoJSON dataset with country and subnational boundaries?
• Should I use Overpass API for this? If so, any tips or queries I could use?
• Are there existing tools or resources to simplify this for app developers?

Thanks a lot for your help!

1 Like

OSM’s boundaries frequently include territorial waters – national boundaries will not follow the coast but be 12 miles out on the sea, and depending on the country this can be the case also for sub-national boundaries. You will likely want to intersect the polygons with a landmass dataset to get boundaries that follow the coast.

To do this, one possible action is to download the planet file, use osmium to filter out all boundary=administrative relations, import these into a PostGIS database with osm2pgsql, import land mass polygons from osmdata.openstreetmap.de (using shp2pgsql), then intersect both data sets in PostGIS. You could also use QGIS to do this interactively.

I am not aware of a publicly available OSM-based GeoJSON dataset for this. Of course you might have a look at naturalearthdata.com which has what they call “admin1” boundaries (the first sub-national level) for many countries. These will not be OSM-based.

1 Like

You can use GeoDesk for this.

  1. Download OpenStreetpMap data in PBF format:
  1. Download the GOL Tool

  2. Create a GOL (a geographic object library) from the PBF data using gol build

  3. Extract the desired admin areas as GeoJSON using gol query, e.g. gol query world a[boundary=administrative][admin_level=2] -f geojson > countries.geojson

As an alternative to Step 4, you can use the GeoDesk Java, Python or C++ toolkits to programmatically query the GOL for specific boundaries (as well as any other OSM features).