I have a full-country data download of OSM from http://download.geofabrik.de/ . I want to extract OSM data for a target area that is thin and winding/irregular in shape. I could take the max-min lat-long bounds,

osmconvert india-latest.osm.pbf -b=${bounds} --complete-ways -o=area1.pbf

.. But that leads to lot of wastage as the rectangle pbf created is many times heavier than the actual area needed. Actually, by taking full rectangle, some settlements with very dense OSM mapping are being included which balloon up the output pbf size like anything. My target area is mostly rural with sparse data. This data has to be churned by a process where minimizing pbf size is of essence to achieve best performance.

If I have my area as a shape in a standard .geojson format shapefile, how do I "clip" the pbf precisely by this shape?


Convert the .geojson to .poly format, then use the -B option in osmconvert.

  1. Grab ogr2poly.py from https://github.com/suke-blog/ogr2poly.py . This is a python2 script.
  2. python2 ogr2poly.py "area.geojson"
  3. This generates a .poly file in the same folder like area_0.poly.
  4. Run osmconvert:
osmconvert india-latest.osm.pbf -B="area_0.poly" --complete-ways -o=area2.pbf

That should create area2.pbf which would be smaller than the rectangle extract. You can preview the output by drag-dropping the .pbf over QGIS (turn off everything else before loading - may take lot of RAM).

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.