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?
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.
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).