Skip to content

Instantly share code, notes, and snippets.

@yohanboniface
Created November 17, 2017 10:41
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 yohanboniface/31ffe8961091483c9eb67f456a905c51 to your computer and use it in GitHub Desktop.
Save yohanboniface/31ffe8961091483c9eb67f456a905c51 to your computer and use it in GitHub Desktop.
Extracting international boundaries from OSM
# put here the name of keys for ways that are assumed to be polygons if they are closed
# see http://wiki.openstreetmap.org/wiki/Map_Features
closed_ways_are_polygons=aeroway,amenity,boundary,building,craft,geological,historic,landuse,leisure,military,natural,office,place,shop,sport,tourism
# comment to avoid laundering of keys ( ':' turned into '_' )
attribute_name_laundering=yes
# uncomment to report all nodes, including the ones without any (significant) tag
#report_all_nodes=yes
# uncomment to report all ways, including the ones without any (significant) tag
#report_all_ways=yes
[multipolygons]
# common attributes
# note: for multipolygons, osm_id=yes instanciates a osm_id field for the id of relations
# and a osm_way_id field for the id of closed ways. Both fields are exclusively set.
osm_id=yes
osm_version=no
osm_timestamp=no
osm_uid=no
osm_user=no
osm_changeset=no
# keys to report as OGR fields
attributes=name,name:fr,name:en,name:ar,name:es,boundary,border_type,admin_level
# keys that should NOT be reported in the "other_tags" field
ignore=area,created_by,converted_by,source,time,ele,note,openGeoDB:,fixme,FIXME
# uncomment to avoid creation of "other_tags" field
other_tags=no
# Get the planet (38G)
wget https://ftp5.gwdg.de/pub/misc/openstreetmap/planet.openstreetmap.org/pbf/planet-latest.osm.pbf
# Install Osmium
git clone https://github.com/osmcode/libosmium.git
git clone https://github.com/osmcode/osmium-tool.git
cd osmium-tool/
mkdir build
cd build
cmake ..
make
# Filter boundaries
./osmium tags-filter ../../planet-latest.osm.pbf r/admin_level=2 -o ../../boundary.osm.pbf
# Transform to SHP with ogr2ogr
ogr2ogr --config OSM_CONFIG_FILE boundary.ini -skipfailures boundary.shp boundaries.osm.pbf -sql "SELECT * FROM multipolygons WHERE admin_level='2'" -lco ENCODING=UTF-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment