3

I want to download country borders as vector data from OpenStreetMap. The best would be in a common vector geodata format like GeoJSON that can be used e.g. in QGIS. I there a simple way to do this?

3

1 Answer 1

4

To download country borders from OpenStreetMap, you can use overpass-turbo.eu. I used the following expression:

[out:json][timeout:25];
relation[boundary=administrative][admin_level=2]["name:en"=Switzerland];
out geom;

Here's a direct link to the query (example country: Switzerland).

Replace the value after "name:en"= with the English name of your country or use name= to query it using the official (short) country name. Don't forget to insert quotes if the name contains spaces or special characters.

You can get the data as GeoJSON via Export > GeoJSON Download. When you load the layer into QGIS, only load the polygons.

A note on country borders including territorial waters: If your country includes a coastline to international waters (maritime borders), the national territory in OSM includes the territorial waters (usually 12 nautical miles from the low-tide coastline). To query only the landmass you might need a workaround when using OSM data. In some countries, downloading all level 4 administrative areas might work. Here's an example for Italy:

[out:json][timeout:25];
{{geocodeArea:Italy}};
relation[admin_level=4][boundary=administrative]["ISO3166-2"~"IT-"](area);
out geom;

Here's a direct link to the query

"ISO3166-2" is used here because without a unique country identifier parts of neighboring countries might be included due to inaccuracies.

Dissolve the layer to one Polygon/MultiPolygon in QGIS to reduce data volume.

However, this does not work for all countries either because no admin level exists that covers only the landmass or because level 4 administrative units also include territorial waters (e.g. Germany).

3
  • 2
    This was an excellent answer, I imported a .GeoJSON into QGIS and exported it out of QGIS as a .SHP
    – MapDeath
    Commented Dec 26, 2023 at 22:13
  • How would I do this for all the smaller admin levels (districts) in Malawi or to get Malawi with all its districts in one geojson? I tried changing the "admin_level=" to a different value but that doesn't seem to have worked. I know OSM has all the sub levels because I can see them on the OSM world basemap in QGIS
    – MapDeath
    Commented Dec 26, 2023 at 22:40
  • You can get all districts like this: [out:json][timeout:25]; relation[admin_level=4][boundary=administrative]["ISO3166-2"~"MW-"]; out geom; Lower levels (e.g. admin_level=8 for municipal level) don't seem to exist for Malawi.
    – winnewoerp
    Commented Dec 26, 2023 at 23:10

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.