osmcode / osmium-tool

Command line tool for working with OpenStreetMap data based on the Osmium library.
https://osmcode.org/osmium-tool/
GNU General Public License v3.0
509 stars 107 forks source link

Invert match does not work #238

Closed saevioapps closed 2 years ago

saevioapps commented 2 years ago

I am trying to run a invert match filter but, the ouput file is exactly the same as the input. This is the command I am running:

osmium tags-filter -i great-britain-latest.osm.pbf \ w/maritime \ -o osmium-output.osm --overwrite

Am I doing something wrong? How do I run an invert match command?

joto commented 2 years ago

What is it that you are trying to achieve?

saevioapps commented 2 years ago

I am trying to remove all ways with the maritime tag from the input file. As I understand, invert match will invert my filter match, so everything except maritime tag. Problem is, no matter what file or filter I use, invert match does not seem to work.

joto commented 2 years ago

Most likely your problem is the automatic "include referenced objects" functionality of osmium tags-filter. By default Osmium will include all objects matching what you want and all objects referenced by those objects. So in this case you might have a way with a maritime=yes tag which would not be included because of your -i and w/maritime but it is still included anyway to complete a relation which has this way as a member. More or less by definition all maritime borders are part of a border relation, so it looks to you like the function is broken, when it is just doing what it is supposed to do.

You can use the -R/-omit-referenced option to ignore the referenced objects, but this will probably not give you what you want either.

Again, I have to ask: What are you trying to achieve in the end? If you tell use what your ultimate goal is, we might have an idea how to achieve this. If you want to render boundaries on land, but not on water, you could try to remove the boundary relations from the file first, before removing the water boundary ways. But this is still brittle, because those ways might be referenced by other relations. Depending on exactly what your needs are there might be different approaches.

saevioapps commented 2 years ago

Yes, I want to render boundaries on land but not on water. I want to remove the boundary that surrounds the land over water. You were right, the ways with maritime tag were referenced by other relations (not tagged maritime) and osmium was adding those ways back to the final result. I tried to remove the relations altogether from the input file but, Mapnik would not render just the ways it seems. What worked was -R (omit referenced) option, which leaves relations with missing ways, but I don't see another way. Thank you so much for your help!

joto commented 2 years ago

You can try the following:

  1. Use osmium cat with -t node -t way option to only get ways and nodes from the input file
  2. Run your osmium export command on that
  3. Use osmium cat with -t relation option to only get the relations from the input file
  4. Concatenate the result of steps 2 and 3 with osmium cat again.

I have not tried this, but it should work. Or you can try using OPL format with something like this:

osmium cat input.osm -f opl | egrep -v '^w.*maritime=yes' | osmium cat - -o output.osm.pbf

There are probably other ways of doing this using the Osmium toolbox.