Combine OpenStreetMap extracts

We discussed previously how to import a single OpenStreetMap extract and avoid processing the huge, complete OSM dataset. What if your area of interest is smaller than the whole planet, but larger than a single extract?

This is what the Luxembourg extract from the previous article looks like.
Luxembourg extract
But what if we want Belgium, Netherlands and Luxembourg?

Osmosis to the rescue. Osmosis is a powerful tool with many options, we'll look at only at the merge option.

  1. Download the extracts - These were from GEOFABRIK
  2. Merge the extracts with osmosis.
  3. cd ~/osmosis/bin/osmosis
    ./osmosis --rx ~/extracts/belgium.osm.bz2 --rx ~/extracts/netherlands.osm.bz2 --rx ~/extracts/luxembourg.osm --merge --merge --wx ~/mapnik/benelux.osm
    from this example you can see that the --read-xml task will work on the bz2-compressed files as well as plain .osm files. If you are merging only two .osm files, omit the second --merge.

  4. Import the merged extract.
  5. cd ../src/osm2pgsql/
    ./osm2pgsql --slim -d gis ~/mapnik/benelux.osm

  6. Set your chosen bounding box in ~/mapnik/generate_image.py. I used ll = (2.54695,49.44722, 7.22760,53.62990) # Benelux
  7. Render your custom area of interestcd ~/mapnik
    source ./set-mapnik-env
    ./customize-mapnik-map >$MAPNIK_MAP_FILE
    ./generate_image.py

And enjoy your newly created, custom area of interest.
Benelux from a combined extract

Credits

Article © 2009 CCBY R.Weait.
Map images and data © 2009 CCBYSA OpenStreetMap and contributors.

Thanks for this article, it

Thanks for this article, it was the reason for me to have a closer look at Osmosis.

But finally I found out that osm2pgsql takes several .osm files as input so it is unnecessary to stick them first together using Osmosis (in case you want to load the data into PostGIS).

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <q> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <h1> <h2> <h3> <h4> <pre> <sup> <sub> <blockquote>
  • Lines and paragraphs break automatically.

More information about formatting options