osmium tags-filter [Options] OSM-FILE FILTER-EXPRESSION...
osmium tags-filter [Options] --expressions=FILE OSM-FILE
Get objects matching at least one of the specified expressions from the input and write them to the output. Expressions can either be specified on the command line or in an expressions file. See the Filter Expressions section for a description of the filter expression format.
All objects matching the expressions will be read from OSM-FILE and written to the output. All objects referenced from those objects will also be added to the output unless the option --omit-referenced/-R is used. This applies to nodes referenced in ways and members referenced in relations.
If the option --omit-referenced/-R is used, the input file is read only once, otherwise the input file will possibly be read up to three times.
Objects will be written out in the order they are found in the OSM-FILE.
The command will only work correctly on history files if the --omit-referenced/-R option is used. The command can not be used on change files.
- -e FILE, --expressions=FILE
Read expressions from the specified file, one per line. Empty lines are ignored. Everything after the comment character (#) is also ignored. See the Filter Expressions section for further details.
- -i, --invert-match
Invert the sense of matching. Exclude all objects with matching tags.
- -R, --omit-referenced
Omit the nodes referenced from matching ways and members referenced from matching relations.
- -t, --remove-tags
Remove tags from objects that are not matching the filter expression but are included to complete references (nodes in ways and members of relations). If an object is both matching the filter and used as a reference it will keep its tags.
- -h, --help
Show usage help.
- -v, --verbose
Set verbose mode. The program will output information about what it is doing to STDERR.
Show progress bar. Usually a progress bar is only displayed if STDOUT and STDERR are detected to be TTY. With this option a progress bar is always shown. Note that a progress bar will never be shown when reading from STDIN or a pipe.
Do not show progress bar. Usually a progress bar is displayed if STDOUT and STDERR are detected to be a TTY. With this option the progress bar is suppressed. Note that a progress bar will never be shown when reading from STDIN or a pipe.
- -F, --input-format=FORMAT
The format of the input file(s). Can be used to set the input format if it can’t be autodetected from the file name(s). This will set the format for all input files, there is no way to set the format for some input files only. See osmium-file-formats(5) or the libosmium manual for details.
- -f, --output-format=FORMAT
The format of the output file. Can be used to set the output file format if it can’t be autodetected from the output file name. See osmium-file-formats(5) or the libosmium manual for details.
Call fsync after writing the output file to force flushing buffers to disk.
The name and version of the program generating the output file. It will be added to the header of the output file. Default is “osmium/” and the version of osmium.
- -o, --output=FILE
Name of the output file. Default is `-' (STDOUT).
- -O, --overwrite
Allow an existing output file to be overwritten. Normally osmium will refuse to write over an existing file.
Add output header option. This command line option can be used multiple times for different OPTIONs. See the osmium-output-headers(5) man page for a list of available header options. For some commands you can use the special format “OPTION!” (ie. an exclamation mark after the OPTION and no value set) to set the value to the same as in the input file.
A filter expression specifies a tag or tags that should be found in the data and the type of object (node, way, or relation) that should be matched.
The object type(s) comes first, then a slash (/) and then the rest of the expression. Object types are specified as `n' (for nodes), `w' (for ways), `r' (for relations), and `a' (for areas - closed ways with 4 or more nodes and relations with
type=boundary tag). Any combination of them can be used. If the object type is not specified, the expression matches all object types.
Matches all nodes with the key “amenity”.
Matches all nodes or ways with the key “highway”.
Matches objects of any type with the key “note”.
Matches objects of any type with the key “note”.
Matches all ways with the key “highway” and value “primary”.
Matches all ways with the key “highway” and a value other than “primary”.
Matches all relations with key “type” and value “multipolygon” or “boundary”.
Matches any way with a “name” or “name:de” tag with the value “Kastanienallee” or “Kastanienstrasse”.
Matches all nodes with any key starting with “addr:”
Matches all nodes with a name that contains the word “Paris”.
Matches any closed ways with 4 or more nodes or relations tagged “building”. Relations must also have a tag “type=multipolygon” or “type=boundary”.
If there is no equal sign (“=”) in the expression only keys are matched and values can be anything. If there is an equal sign (“=”) in the expression, the key is to the left and the value to the right. An exclamation sign (“!”) before the equal sign means: A tag with that key, but not the value(s) to the right of the equal sign. A leading or trailing asterisk (“*”) can be used for substring or prefix matching, respectively. Commas (“,”) can be used to separate several keys or values.
All filter expressions are case-sensitive. There is no way to escape the special characters such as “=”, “*” and “,”. You can not mix comma-expressions and “*”-expressions.
The filter expressions specified in a file and/or on the command line are matched in the order they are given. To achieve best performance, put expressions expected to match more often first.
Area matches (with leading “a/”) do not check whether the matched object is a valid (multi)polygon, they only check whether an object might possibly be turned into a (multi)polygon. This is the case for all closed ways (where the first and last node are the same) with 4 or more nodes and for all relations that have an additional “type=multipolygon” or “type=boundary” tag.
osmium tags-filter exits with exit code
if everything went alright,
if there was an error processing the data, or
if there was a problem with the command line arguments.
osmium tags-filter does all its work on the fly and only keeps tables of object IDs it needs in main memory. If the --omit-referenced/-R option is used, no IDs are kept in memory.
Get all amenity nodes from the Berlin PBF file:
osmium tags-filter -o amenties.osm.pbf berlin.osm.pbf n/amenity
Get all objects (nodes, ways, or relations) with a
osmium tags-filter -R -o notes.osm.pbf berlin.osm.pbf note
Get all nodes and ways with a
highway tag and all relations tagged with
type=restriction plus all referenced objects:
osmium tags-filter -o filtered.osm.pbf planet.osm.pbf \ nw/highway r/type=restriction
Copyright (C) 2013-2021 Jochen Topf <email@example.com>.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
If you have any questions or want to report a bug, please go to https://osmcode.org/contact.html
Jochen Topf <firstname.lastname@example.org>.