This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

tags-filter with multiple filter expressions not working as expected?

0

I am trying to get all main railway tracks from an .osm.pbf file. My command looks like this:

osmium tags-filter austria-latest.osm.pbf railway=rail railway:track_type=main service!=yard service!=siding -o rails_in_austria.osm.pbf

My expectation was that osmium will match the file against all four filter expressions sequentially similar to a logical & operator. Somehow this doesn't seem to happen as my result contains entries that e.g. do not contain any railway attribute.

The man page for osmium-tags-filter says:

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.

I'm stuck here, maybe more experienced users can help?

In QGis my filter works with following SQL filter expression:

"other_tags" LIKE '%"railway:track_type"=>"main"%' AND "other_tags" NOT LIKE '%"service"=>"yard"%' AND "other_tags" NOT LIKE '%"service"=>"siding"%'

asked 25 Dec '21, 13:29

pato3's gravatar image

pato3
11112
accept rate: 0%


One Answer:

0

The first sentence of the man page should make things clear: "Get objects matching at least one of the specified expressions from the input and write them to the output." So the expressions are ORed together. You can not do general AND expressions. Sometimes what you want can be done using inverted expressions and the -i option. Or you run Osmium several times, once each with the expressions you want ANDed.

Generally osmium tags-filter is more suited to to a rough filtering (in your case the railway=rail) which will reduce the data from "huge amounts of data" to "manageable amount of data" quickly. Then just use any other kind of specialized processing you want to do with whatever tool suits you best.

answered 25 Dec '21, 17:25

Jochen%20Topf's gravatar image

Jochen Topf
5.2k55074
accept rate: 31%

Source code available on GitHub .