How to handle conflicting filters in osmfilter

How do I configure a mutually exclusive combination of keep- and drop- options in osmfilter?

I want to discard any tracks --drop="highway=track" unless they have a --motor_vehicle=permissive tag, in which case I want to say --keep="motor_vehicle=permissive"

Is there a way to combine AND or OR to cleverly combine the drop and keep options? In short, I only want to keep highway=track if motor_vehicle=permissive. All other tracks can be dropped. Thanks

You can use “boolean operators” to define complex filters.

Thanks @ImreSamu but it’s not clear how to combine a keep and a drop with boolean operators, as the example uses ‘or’ and brackets as qualifiers for the keep option. I have a long list of filters for the first part of the ‘or’, and the second part is just --keep="motor_vehicle=permissive"

But it’s not as straightforward as I thought. Thanks for the suggestion though

I’m not sure what issue you’re trying to solve.

for example, If you only want to keep roads where cars are allowed,
you can do that using the --keep option.

  • ( highway=track and motor_vehicle=permissive )
osmfilter hungary.o5m --ignore-dependencies \
      --keep=" highway=primary =secondary =residential  or ( highway=track and motor_vehicle=permissive ) " \
      --out-o5m > wanted.o5m
osmfilter wanted.o5m --out-count=highway
     178021	residential
      32818	secondary
      24916	primary
         91	track

Recently, I’ve been using pyosmium in Python3 for more complicated filtering tasks
and only using osmfilter for simpler stuff.

Sorry, I’m not familiar enough with the osmfilter command to know how to complexly combine the keep and drop options.

1 Like

Try doing as a colleague above advises, I also use pyosmium in Python3, and it actually works very well at the moment. As for the issue of dropping and storing, I’m not able to help you at the moment either, although it’s probably possible with osmfilter.