OSMFILTER(1)
๐ OSMFILTER ๐
the experimental OSM filter thingy, bestie. osmfilter โ The experimental OSM filters data. she's a whole main character and she's built different, but also she bites, so read the warning, okay? ๐ซถ
๐ SYNOPSIS ๐
osmfilter options [input file]
โจ DESCRIPTION โจ
THIS PROGRAM IS FOR EXPERIMENTAL USE ONLY. PLEASE EXPECT MALFUNCTION AND DATA LOSS. SAVE YOUR DATA BEFORE STARTING THIS PROGRAM.
No seriously. Not me being dramatic for once. EXPERIMENTAL. MALFUNCTION. DATA LOSS. Back up your files before you run this, periodt. ๐ญ
So like, this program filters OpenStreetMap data. That's the whole vibe. ๐บ๏ธ
The input file name has to be handed over as a command line argument โ you literally cannot skip this. And the file must not be a stream. Redirecting from standard input? Not happening, sorry babe. The program needs random access to the file, so a stream just won't do. ๐
Good news tho: you do not need to tell her what the input format is, because osmfilter recognizes these all on her own:
.osm(XML).osc(OSM Change File).osh(OSM Full History).o5m(speed-optimized).o5c(speed-optimized Change File)
The output format is .osm by default. Want something different? Specify it with the appropriate command line parameter and she'll switch it up. ๐
๐ OPTIONS ๐
--keep=OBJECT_FILTERโ Every object type (nodes, ways and relations) gets kept if it meets the filter criteria. Same energy for dependent objects too, like nodes inside ways, ways inside relations, relations inside other relations. Wanna know theOBJECT_FILTERsyntax? It's down below, keep scrolling. ๐--keep-nodes=OBJECT_FILTER,--keep-ways=OBJECT_FILTER,--keep-relations=OBJECT_FILTER,--keep-nodes-ways=OBJECT_FILTER,--keep-nodes-relations=OBJECT_FILTER,--keep-ways-relations=OBJECT_FILTERโ Same as the one above, but only for the object types you actually named. Cherry-picking, iconic. ๐--drop=OBJECT_FILTERโ Every object type (nodes, ways and relations) that meets the filter criteria gets dropped, no matter what โ even if it also meets the criteria of a keep filter (see above). So yeah, drop beats keep.OBJECT_FILTERsyntax is below. ๐๏ธ--drop-nodes=OBJECT_FILTER,--drop-ways=OBJECT_FILTER,--drop-relations=OBJECT_FILTER,--drop-nodes-ways=OBJECT_FILTER,--drop-nodes-relations=OBJECT_FILTER,--drop-ways-relations=OBJECT_FILTERโ Same as above, but just for the object types you specified.--keep-tags=TAG_FILTERโ The tags you name inTAG_FILTERare the ones allowed on output.TAG_FILTERsyntax lives below, go look. ๐ท๏ธ--keep-node-tags=TAG_FILTER,--keep-way-tags=TAG_FILTER,--keep-relation-tags=TAG_FILTER,--keep-node-way-tags=TAG_FILTER,--keep-node-relation-tags=TAG_FILTER,--keep-way-relation-tags=TAG_FILTERโ Same as above, but only for the object types you named.--drop-tags=TAG_FILTERโ The tags you specify get dropped. And yes, this overrules the--keep-tagsparameter we just talked about. She said what she said.TAG_FILTERsyntax is below.--drop-node-tags=TAG_FILTER,--drop-way-tags=TAG_FILTER,--drop-relation-tags=TAG_FILTER,--drop-node-way-tags=TAG_FILTER,--drop-node-relation-tags=TAG_FILTER,--drop-way-relation-tags=TAG_FILTERโ Same as above, but only for the object types you specified.--modify-tags=TAG_MODIFICATION_LISTโ The tags you list get modified. This happens after any filtering (so after--keep,--keep-tags,--drop,--drop-tagsโ order matters, bestie).TAG_MODIFICATION_LISTis described below. โ๏ธ--modify-node-tags=TAG_MODIFICATION_LIST,--modify-way-tags=TAG_MODIFICATION_LIST,--modify-relation-tags=TAG_MODIFICATION_LIST,--modify-node-way-tags=TAG_MODIFICATION_LIST,--modify-node-relation-tags=TAG_MODIFICATION_LIST,--modify-way-relation-tags=TAG_MODIFICATION_LISTโ Same as above, but only for the object types you specified.--drop-authorโ For most applications the author tags are just not needed, fr fr. Flip this on and no author information gets written at all: no changeset, no user, no timestamp. Poof. ๐ซฅ--drop-versionโ Wanna exclude not just the author info but the version number too? This is your girl.--drop-nodes,--drop-ways,--drop-relationsโ Depending on which combo of these you pick, no members of the referred section get written.--emulate-osmosis,--emulate-pbf2osmโ If the output format is.osm, the program will try to use the same data syntax as Osmosis, or respectively pbf2osm. Copying their whole flow. ๐--fake-authorโ If you dropped author info with--drop-author, that data is gone, obviously, that's what dropping means. But some programs require author information on input even though they don't actually need the data. So for that, you can fake it.o5mfilerwill write changeset 1, timestamp 1970. โณ--fake-versionโ Same as--fake-author, except that โ if.osmXML is used as the output format โ only the version number gets written (version 1). Super useful if you wanna inspect the data with JOSM. ๐--fake-lonlatโ Some programs depend on getting longitude/latitude values, even when the object in question is supposed to be deleted. With this option you can haveosmfilterfake those values:
... lat="0" lon="0" ...
Heads up: this is for XML files only (.osc and .osh).
-hโ Displays a short parameter overview. Quick lil peek. ๐--helpโ Displays this help.--ignore-dependenciesโ Usually, all member nodes of a way that meets the filter criteria get included too. Same goes for members of included relations. Activate this option and all those dependencies between OSM objects get ignored. Cutting the strings. โ๏ธ--out-key=KEYNAMEโ The output won't contain regular OSM data, just statistics: a list of all used keys gets assembled. To the left of each key, the number of occurrences is printed. IfKEYNAMEis given, the program lists all values used in connection with that key. You can use wildcard characters forKEYNAME, but only at the beginning and/or at the end. For example:
--out-key=addr:*
--out-count=KEYNAMEโ Same as--out-key=, except the list is sorted by the number of occurrences of the keys, or respectively the values. Sorted by popularity, she's ranking them. ๐--out-osmโ Data gets written in.osmformat. This is the default output format.--out-oscโ The OSM Change format gets used for output. Just so you know: OSM objects that are meant to be deleted are represented by their ids only.--out-oshโ For every OSM object, the appropriate'visible'tag gets added, to meet the 'full planet history' specification. ๐--out-o5mโ The.o5mformat gets used. Same structure as the conventional.osmformat, but the data is stored as binary numbers, so it's much more compact than.osm. No packing is used, which means you can pack.o5mfiles with any file packer you want โlzo,bz2, etc. ๐๏ธ--out-o5cโ This is the change file format of the.o5mdata format. All<delete>tags won't be performed as delete actions, they get converted into.o5cdata format instead.-o=<outfile>โ Standard output gets rerouted to the file you specify. And if no output format has been specified, the program figures it out from the file name extension. Clever girl. ๐ง-t=<tempfile>โosmfilteruses a temporary file to process interrelational dependencies, and this parameter defines the name prefix. Default value is"osmfilter_tempfile".--parameter-file=FILEโ Wanna supply one or more command line arguments through a parameter file? Use this option and give the file name. Inside the parameter file, parameters must be separated by empty lines. Line feeds inside a parameter get converted to spaces. And lines starting with"// "are treated as comments. ๐-v,--verboseโ With 'verbose' mode activated, some statistical data and diagnosis data gets displayed. And if-vor--verboseis the first parameter in the line,osmfilterwill display all input parameters. Spilling all the tea. โ
๐ฆ OBJECT_FILTER ๐ฆ
Some of the command line arguments need a filter, and this filter definition is made of key/val pairs. Here's the syntax:
"KEY1=VAL1 OP KEY2=VAL2 OP KEY3=VAL3 ..."
OP is the Boolean operator, and it must be either "and" or "or". As usual, "and" gets processed before "or". Wanna control the order of processing yourself? Use brackets. Just know that brackets always have to be padded by spaces. Example:
lit=yes and ( note=a or source=b )
Instead of every "=" you can enter one of these comparison operators: != (not equal), <, >, <=, >=. The program uses ASCII-alphabetic comparison, unless you're comparing against a value that starts with a digit.
If there are different possible values for the same key, you only need to write the key once. For example:
"amenity=restaurant =pub =bar"
It's also allowed to omit the value entirely โ in that case the program accepts every value for the defined key. For example:
"highway= and lit=yes"
You may use wildcard characters for a key or a value, but again โ only at the beginning and/or at the end. For example:
"wikipedia:*=highway=*ary ref_name=*central*"
โ ๏ธ Be careful with wildcards in keys, because only the first key that meets the pattern gets processed. First come, first served, and the rest are just standing there. ๐
There are three special keys that represent object id, user id and user name: @id, @uid and @user. They let you search for certain objects, or for edits made by specific users. ๐ต๏ธโโ๏ธ
๐ธ TAG_FILTER ๐ธ
The tag filter decides which tags get kept and which don't. For example:
--keep-tags="highway=motorway =primary"
...will not accept "highway" tags other than "motorway" or "primary". And note: neither the object itself gets deleted, nor the remaining tags. She's just being selective about the tags, not throwing the whole thing out.
If you wanna drop every tag that isn't mentioned in a list, use this example:
all highway= amenity= name=
๐ TAG_MODIFICATION_LIST ๐
The tag modification list decides which tags get modified. So like, this example:
--modify-tags="highway=primary to =secondary"
...will change every "primary" highway into "secondary". A total glow-up. โจ
You can also use comparisons, or add additional tags:
--modify-way-tags="maxspeed>200 add highspeed=yes"
๐๏ธ TUNING ๐๏ธ
Okay so bestie, here's the tea on making this go fast โโจ
To speed up the whole process, osmfilter uses some main memory for a hash table. By default it grabs 1200 MB to store a flag for every possible node, 150 for the way flags, and 10 relation flags. And here's the cute part โ every single byte holds the flags for 8 ID numbers, which means in 1200 MB the program can store 9600 million flags. Iconic capacity, honestly. ๐
Now, since there are fewer than 5700 million IDs for nodes at present (that's May 2018, bestie, so like, ancient history but okay), 720 MB would totally suffice. So for example, you can shrink the hash sizes down to like 720, 80 and 2 MB (and heads up โ for relations, 2 flags are needed each) using this option:
--hash-memory=720-80-2
But bestie, keep in mind the OSM database is continuously expanding. It never stops growing, she's always eating. ๐ฝ๏ธ For this reason the program's own default value is higher than what's shown in the example, and it may be appropriate to increase it in the future.
If you do not want to bother with all the details, you can just enter the amount of memory as a sum and the program will divide it by itself. Like:
--hash-memory=1000
Those 1000 MiB get split into three parts: 800 for nodes, 150 for ways, and 50 for relations. Slay, math done for you. ๐งฎโจ
And because we're taking hashes, you don't have to provide all the suggested memory โ the program will operate with less hash memory too. But (and this is the important bit, no cap) in that case the border filter will be less effective, i.e., some ways and some relations will be left in the output file even though they should have been excluded. So like, you get leftovers you didn't order. ๐
The maximum value the program accepts for the hash size is 4000 MiB. If you exceed the maximum amount of memory available on your system, the program will try to reduce this amount and display a warning message. It's looking out for you fr fr. ๐ซถ
๐ง LIMITATIONS ๐ง
When you're filtering whole OSM objects (--keep...=, --drop...=), the input file must contain the objects ordered by their type: first, all nodes nodes, next, all ways, followed by all relations. Yes, that's the ordering. The order matters, bestie, don't fight it. ๐
Usual .osm, .osc, .o5m and o5c files adhere to this condition. So this means you do not have to worry about this limitation at all. Phew. ๐ And if this sequence does get broken, osmfilter will display an error message โ it will absolutely call it out, periodt.
The number of key/val pairs in each filter parameter is limited to 1000, and the length of each key or val is limited to 100. That's the ceiling, babe. ๐
๐ NOTES ๐
This program is for experimental use. Expect malfunctions and data loss. Do not use the program in productive or commercial systems.
Like, for real for real. Do not put this in prod. I am begging you. ๐ญ๐
There is NO WARRANTY, to the extent permitted by law. Please send any bug reports to marqqs@gmx.eu โ he wants to hear from you, bestie. ๐๐ฌ
๐ EXAMPLE ๐
Here's the vibe, copy-paste ready:
osmfilter europe.o5m --keep=amenity=bar -o=new.o5m
osmfilter a.osm --keep-nodes=lit=yes --drop-ways -o=light.osm
osmfilter a.osm --keep="place=city or ( place=town and population>=10000
)" -o=b.osm
osmfilter region.o5m --keep="bridge=yes and layer>=2" -o=r.o5m
Look at those. Literally so satisfying. ๐ฅ
๐ SEE ALSO ๐
Go read those too, they're part of the friend group. ๐ซ
๐ AUTHORS ๐
osmfilter was written by Markus Weber. Legend behaviour, honestly. ๐
And that's the whole page, bestie! This one came from the source/version line and the date stamp at the bottom โ September 2013, filed under OSMFILTER(1). Ancient relic, still serving looks. ๐โจ Go filter something. Mwah. ๐
๐ฆ where this page comes from
- debian bookworm: osmctools 0.9-4 ยท AGPL-3.0-only
- debian trixie: osmctools 0.9-5 ยท AGPL-3.0-only
- epel 10: osmctools 0.9-16.el10_0 ยท AGPL-3.0-only AND GPL-2.0-or-later
- epel 9: osmctools 0.9-12.el9 ยท AGPLv3 and GPLv2+
- fedora 43: osmctools 0.9-19.fc43 ยท AGPL-3.0-only AND GPL-2.0-or-later
- fedora 44: osmctools 0.9-21.fc44 ยท AGPL-3.0-only AND GPL-2.0-or-later
- ubuntu jammy: osmctools 0.9-3 ยท AGPL-3.0-only
- ubuntu noble: osmctools 0.9-4 ยท AGPL-3.0-only
- ubuntu questing: osmctools 0.9-5
- ubuntu resolute: osmctools 0.9-5build1 ยท AGPL-3.0-only
- ubuntu stonking: osmctools 0.9-5build1 ยท AGPL-3.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms