Osmium Command Examples (with Examples)
1: Show File Information
osmium fileinfo path/to/input.osm
Motivation: This command is used to display information about an OSM file. It is useful to quickly gather metadata about the OSM file before performing any further operations.
Explanation:
osmium fileinfo
: The command to display file information.path/to/input.osm
: The path to the OSM file for which the information is to be displayed.
Example Output:
File: path/to/input.osm
Generator: Osmium-Tool 1.14.1
Timestamp: 2021-04-20T10:30:00Z
Nodes: 15000
Ways: 2000
Relations: 500
2: Display Contents
osmium show path/to/input.osm
Motivation: This command allows us to view the contents of an OSM file. It can be helpful to analyze the data, inspect the tags, and understand the structure.
Explanation:
osmium show
: The command to display the contents of the OSM file.path/to/input.osm
: The path to the OSM file to be displayed.
Example Output:
<osm version="0.6" ...>
<node id="123" ... />
<way id="456" ... />
<relation id="789" ... />
</osm>
3: Convert File Format from PBF into XML
osmium cat path/to/input.osm.pbf -o path/to/output.osm
Motivation: This command is useful when we need to convert an OSM file from one format to another. In this case, we convert from PBF (Protocolbuffer Binary Format) to XML.
Explanation:
osmium cat
: The command to concatenate OSM files.path/to/input.osm.pbf
: The path to the input PBF file.-o path/to/output.osm
: The output file path with the converted format.
Example Output:
The file at path/to/output.osm will contain the contents of the input PBF file in XML format.
4: Extract a Geographic Region by Bounding Box
osmium extract -b min_longitude,min_latitude,max_longitude,max_latitude path/to/input.pbf -o path/to/output.pbf
Motivation: This command allows us to extract a specific geographic region from an OSM file. It is useful when we are only interested in a particular area and want to reduce the data size.
Explanation:
osmium extract
: The command to extract a geographic region.-b min_longitude,min_latitude,max_longitude,max_latitude
: Bounding box coordinates defining the region to extract.path/to/input.pbf
: The path to the input PBF file.-o path/to/output.pbf
: The output file path for the extracted region.
Example Output:
The file at path/to/output.pbf will contain the extracted region defined by the bounding box coordinates.
5: Extract a Geographic Region by GeoJSON File
osmium extract -p path/to/polygon.geojson path/to/input.pbf -o path/to/output.pbf
Motivation: This command allows us to extract a specific geographic region from an OSM file using a GeoJSON file. It is useful when we have a polygon shape defined in GeoJSON format.
Explanation:
osmium extract
: The command to extract a geographic region.-p path/to/polygon.geojson
: The path to the GeoJSON file containing the polygon shape.path/to/input.pbf
: The path to the input PBF file.-o path/to/output.pbf
: The output file path for the extracted region.
Example Output:
The file at path/to/output.pbf will contain the extracted region defined by the polygon shape in the GeoJSON file.
6: Filter Objects Tagged as “Restaurant”
osmium tags-filter path/to/input.pbf amenity=restaurant -o path/to/output.pbf
Motivation: This command is useful when we want to filter specific objects in an OSM file that have a specific tag. In this case, we are filtering objects tagged as “restaurant”.
Explanation:
osmium tags-filter
: The command to filter objects by tags.path/to/input.pbf
: The path to the input PBF file.amenity=restaurant
: The tag condition to match for filtering objects.-o path/to/output.pbf
: The output file path for the filtered objects.
Example Output:
The file at path/to/output.pbf will contain only the objects tagged as "restaurant" from the input PBF file.
7: Filter “Way” Objects Tagged as “Highway”
osmium tags-filter path/to/input.pbf w/highway -o path/to/output.pbf
Motivation: This command is useful when we want to filter specific objects in an OSM file based on their type (i.e., “way”) and tags. In this case, we are filtering “way” objects tagged as “highway”.
Explanation:
osmium tags-filter
: The command to filter objects by tags.path/to/input.pbf
: The path to the input PBF file.w/highway
: The tag condition to match for filtering “way” objects tagged as “highway”.-o path/to/output.pbf
: The output file path for the filtered objects.
Example Output:
The file at path/to/output.pbf will contain only the "way" objects tagged as "highway" from the input PBF file.
8: Filter “Way” and “Relation” Objects Tagged as “Building”
osmium tags-filter path/to/input.pbf wr/building -o path/to/output.pbf
Motivation: This command is useful when we want to filter specific objects in an OSM file based on their type (i.e., “way” and “relation”) and tags. In this case, we are filtering “way” and “relation” objects tagged as “building”.
Explanation:
osmium tags-filter
: The command to filter objects by tags.path/to/input.pbf
: The path to the input PBF file.wr/building
: The tag condition to match for filtering “way” and “relation” objects tagged as “building”.-o path/to/output.pbf
: The output file path for the filtered objects.
Example Output:
The file at path/to/output.pbf will contain only the "way" and "relation" objects tagged as "building" from the input PBF file.