Skip to content

Instantly share code, notes, and snippets.

@andrashann
Created November 4, 2022 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrashann/af7a1dfec359d3ec23ff3c5024c7458d to your computer and use it in GitHub Desktop.
Save andrashann/af7a1dfec359d3ec23ff3c5024c7458d to your computer and use it in GitHub Desktop.
get country borders from planet-latest.osm.pbf openstreetmap export using osmium into a geojson file
# on a Mac: brew install osmium-tool
# get relations with boundary=administrative tag, use -t to throw away unneeded tag info
# (otherwise a bunch of unneeded objects remain)
osmium tags-filter -t -o bound.osm.pbf planet-latest.osm.pbf r/boundary=administrative
# same, but filtering futher for admin_level=2
osmium tags-filter -t -o admin_level_2.osm.pbf bound.osm.pbf r/admin_level=2
#convert to geojson for further processing
osmium export admin_level_2.osm.pbf -o admin_level_2.geojson
# note: disputed territories might be a part of _both_ countries in this dataset.
# note2: this ran in a couple of minutes (for the whole planet!) on a machine with an M1 Pro processor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment