Osmium and Osmosis command tools have the capability of extracting a geographic extent from an OSM file.

--read-xml test.osm --tee 1
--bounding-box left=15 top=46 --write-xml extract_test.osm

osmium extract -p city.geojson test.pbf -o extract_test.pbf

What I need is to extract region from an OSM file like a city and after some edits, merge it with the OSM file with the hole (excluded the city region). How can I exclude or clip a geographic extent from original file?

1 Answer 1


GeoJSON polygons are allowed to have holes, and Osmium does in fact support this.

So you could construct a polygon where ...

  • ... the outer ring is large enough to contain all the data in the original file
  • ... the inner ring is the boundary of the city you want to exclude.

Running osmium extract with that polygon as the -p parameter would remove data inside the inner ring and yield the desired result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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