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.

  1. Download the planet OSM in XML or PBF format

  2. 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

  3. Simplify the geometries to help with the file size without losing track of which features are "inside" other features.

  4. 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.


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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.