Add logical_operator parameter for AND/OR tag filtering 🪛 #223
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new
filter_logical_operator
parameter to all QuackOSM converter functions, allowing users to control how tags_filter conditions are logically combined. Choose between "OR" (default) and "AND" logic when filtering OSM features by tags 🏷️Motivation
When filtering with multiple tag conditions, QuackOSM returns features matching ANY of these conditions (OR logic). In many cases, you actually want to filter features that match ALL conditions (AND logic). Without this possibility I would first use quackosm to produce a result set and then add on a second processing step to filter the results. This PR allows returning only features that match all specified conditions directly.
eg) if you only want gravel tracks, you could combine
highway=track
andsurface=gravel
. However with the current (AND) logic, many rows would be included that do not fit eg) asphalt tracks and anything tagged to be gravel.Changes
filter_logical_operator
parameter and uses the relevantAND
orOR
logic in formatted SQL query.filter_logical_operator
parameter and pass it to the PbfFileReader.Note
I didn't think about how this might work with the negative filtering.. For my use case I don't need it, so it didn't come up, sorry that I didn't think it through.
I also didn't add any tests, as I don't know how to do it in this codebase. If you can point me in the right direction, I would be happy to add some tests.
p.s. Thanks for this tool! It works great and is a real benefit to the community. Really appreciate the work you put into it 🙏