I am trying to create a multi-level choropleth map based on OSM data.
I need the outline/boundaries. I would like to do this from the command line if possible.
Here is what I think the steps should be.
-
Download the planet OSM in XML or PBF format
-
Extract the administrative boundaries for features with an admin level of 2, 4, 6 or 8. This is my current attempt:
osmconvert planet-latest.osm.pbf -o=planet.o5m osmfilter planet.o5m --keep-nodes= --keep-ways-relations="boundary=administrative and (admin_level=2 or admin_level=4 or admin_level=6 or admin_level=8)" > planet.osm
-
Simplify the geometries to help with the file size without losing track of which features are "inside" other features.
-
Convert the final product into GeoJSON.
I am struggling with #2 the most and it seems like the most important step.
If any other process I should try, please let me know.
Best Answer
Instead of downloading the xml/pbf file and filtering for the tags using osmfilter. you should use the overpass api that will give you filtered results. the api will search for filtered queries like
admin_level=2 or admin_level=4 or admin_level=6 or admin_level=8
hence it will be much faster than any other method.Here is an example that gives out
admin_level = 2
, http://overpass-turbo.eu/s/yv2