Osmosis/Examples
This page gives some more obscure or convoluted examples of Osmosis usage. For basic usage examples see Osmosis#Example Usage. For reference documentation of the various options see Osmosis/Detailed Usage
Contents |
Misc. examples
- Setting up a local database copy with minutely diffs
- 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
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 users, a cheap and really fast method for this specific task would be to use osmchange instead of Osmosis. Some examples:
cat europe.osm | ./osmchange -B=hamburg.poly >hamburg.osm bzcat europe.osm.bz2 | ./osmchange -B=hamburg.poly |bzip2 >hamburg.osm.bz2 gunzip europe.osm.gz | ./osmchange -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.
- Alternatives
Presumably the fastest tools which extract a region from a .pbf file are pbftoosm and osmconvert. Both tools are available for Linux and Windows.