Osmosis/Examples
This page gives some more complex examples. See Osmosis#Example usage for more examples. For reference documentation of the various options see Osmosis/Detailed Usage
Misc. examples
- Setting up a local copy of the OpenStreetMap database, kept up to date with minutely diffs
- Osmosis/keep a local copy of a .osm file updated using minutely updates
- Tutorial: A Self-Updating Local OpenStreetMap Extract - shows various osmosis reading, writing, filtering and replication tasks in a real world use case.
- User:Firefishy/za-rail-script - setting up replication within a bash script
Extract administrative Boundaries from a PBF Extract
The following will create an extract that only consists of administrative boundaries within a specifieed polygon.
osmosis --read-pbf file=ohio.osm.pbf --bounding-polygon file=input.poly --tf accept-ways boundary=administrative --used-node --write-xml output.osm
Breaking OSM file into several bounding boxes
The following command line breaks Slovenia OSM into four "quadrants" around lat=15, long=46 axis:
osmosis --read-xml SloveniaGarmin.osm --tee 4 --bounding-box left=15 top=46 --write-xml SloveniaGarminSE.osm --bounding-box left=15 bottom=46 --write-xml SloveniaGarminNE.osm --bounding-box right=15 top=46 --write-xml SloveniaGarminSW.osm --bounding-box right=15 bottom=46 --write-xml SloveniaGarminNW.osm
(NOTE: the order of operations is important. This sample works for Osmosis version 0.29)
If you have more than 20 bboxes, you should use bboxSplit instead. It is much faster an uses a lot less memory when working with the complete planet.
Breaking out a large number of polygons
The following command line breaks out 16 individual bz2 files for the German Federal States (all to be written on one line without the backslashes, or copy/pasted including the backslashes and no trailing spaces):
osmosis \ --rx full/planet-071128.osm.bz2 \ --tee 16 \ --bp file=polygons/europe/germany/baden-wuerttemberg.poly \ --wx baden-wuerttemberg.osm.bz2 \ --bp file=polygons/europe/germany/bayern.poly \ --wx bayern.osm.bz2 \ --bp file=polygons/europe/germany/berlin.poly \ --wx berlin.osm.bz2 \ --bp file=polygons/europe/germany/brandenburg.poly \ --wx brandenburg.osm.bz2 \ --bp file=polygons/europe/germany/bremen.poly \ --wx bremen.osm.bz2 \ --bp file=polygons/europe/germany/hamburg.poly \ --wx hamburg.osm.bz2 \ --bp file=polygons/europe/germany/hessen.poly \ --wx hessen.osm.bz2 \ --bp file=polygons/europe/germany/mecklenburg-vorpommern.poly \ --wx mecklenburg-vorpommern.osm.bz2 \ --bp file=polygons/europe/germany/niedersachsen.poly \ --wx niedersachsen.osm.bz2 \ --bp file=polygons/europe/germany/nordrhein-westfalen.poly \ --wx nordrhein-westfalen.osm.bz2 \ --bp file=polygons/europe/germany/rheinland-pfalz.poly \ --wx rheinland-pfalz.osm.bz2 \ --bp file=polygons/europe/germany/saarland.poly \ --wx saarland.osm.bz2 \ --bp file=polygons/europe/germany/sachsen-anhalt.poly \ --wx sachsen-anhalt.osm.bz2 \ --bp file=polygons/europe/germany/sachsen.poly \ --wx sachsen.osm.bz2 \ --bp file=polygons/europe/germany/schleswig-holstein.poly \ --wx schleswig-holstein.osm.bz2 \ --bp file=polygons/europe/germany/thueringen.poly \ --wx thueringen.osm.bz2
If the part "osmosis --rx full/planet-071128.osm.bz2" in the above example doesn't work for you, use "bzcat full/planet-071128.osm.bz2 |osmosis --rx /dev/stdin" instead of it.
Splitting out 16 polygons takes about 30% more time than splitting out only one.
Performance can be improved by
- not using .bz2
- first cutting out an Europe or Germany bbox and operating on that
See also: Osmosis/Polygon_Filter_File_Format
See this Geofabrik blog entry for an extensive example of polygon splitting.
Breaking out just one polygon
For Linux and Windows users, a cheap and really fast method for this specific task would be to use osmconvert instead of Osmosis. Some examples:
./osmconvert europe.osm -B=hamburg.poly -o=hamburg.osm ./osmconvert europe.pbf -B=hamburg.poly -o=hamburg.pbf bzcat europe.osm.bz2 | ./osmconvert - -B=hamburg.poly |bzip2 >hamburg.osm.bz2 ./osmconvert europe.osm.gz -B=hamburg.poly |gzip -1 >hamburg.osm.gz
Note: It is much faster to compress files with gzip -1 than with bzip2. Although the compressed file will be about 50 % larger, the compression process will be up to 10 times faster.