-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] re-design of AND versus OR queries #255
Comments
Similar to what @Mashin6 said in the mentioned issue, I believe it would make a lot more sense for newcomers to:
The name That would fit better the way most people would read the code, replacing the pipe with "then":
Adapting Mashin6's hypothetical example, a sample command would look like this: opq() |>
get_osm_features(match_all = c("natural = tree", "leaf_type = broadleaved")) |>
get_osm_features(match_all = c("leisure = park", "name ~ public")) |>
get_osm_features(key = "amenity", value = "bench") ... which would return an opq object that would retrieve broad leaved trees, benches, and parks with "public" in their name. In the meantime, I'm wondering if aliasing |
I'm also thinking an ellipsis argument could be used instead of a opq() |>
get_osm_features("natural = tree", "leaf_type = broadleaved") |>
get_osm_features("leisure = park", "name ~ public") |>
get_osm_features(key = "amenity", value = "bench") Edit: hmm that could easily be misinterpreted as an OR.... e.g. people trying things like ...or should there be two unambiguous arguments |
This name change looks like a good strategy for transition. |
I just played a bit around with the package some years ago - so please don't consider my thoughts as important... Building on @stragu's comments, I was just wondering, if you could pass named arguments to the ellipsis in the style of I think it's completely OK that passing multiple corresponds to a logical AND, as I'm used to this by A similar idea was to approach it as expressions that return a logical vector like Anyways thank you for the package! Really hope to use it more one day. |
Is there any consensus about the API or somebody working on it? The easier thing could be to modify the existing functions and make I can try this approach and see what else is needed to make it work. |
I found that:
I would like to make possible to chain |
Got the code working at jmaspons@2ccf6d1 |
Thanks, that's a useful fix. Though I don't think it addresses the main point of this issue. IMO the solution would be to soft deprecate both
|
Yes, I agree that the current naming is not very explicit and can be improved, but the docs are quite clear. The problem I see is that the proposed solution is not as powerful, as it doesn't allow to chain features with AND or OR in arbitrary order. For example, is not possible to chain and OR followed but an AND as in waterarea<- list(waterway='riverbank',
landuse=c('reservoir', 'water', 'basin', 'salt_pond'),
natural=c('lake', 'water'),
amenity='swimming_pool',
leisure = 'swimming_pool') # minzoom: 12
waterway_low<- list(waterway=c('river','canal')) # minzoom: 8, maxzoom: 12
placenames_small<- list(place=c('suburb','village','locality','hamlet','quarter','neighbourhood','isolated_dwelling','farm')) # minzoom: 10; maxzoom: 17
mainroad_label<- list(highway=c('primary', 'secondary', 'tertiary')) # minzoom: 12
leisure_label<- list(leisure=c('park', 'sports_centre', 'stadium', 'pitch')) # minzoom: 14
objects_osm<- c(waterarea, waterway_low, placenames_small, mainroad_label, leisure_label)
areaPPCC<- getbb("Països Catalans", format_out="data.frame")
consulta<- opq(areaPPCC, out="tags center", osm_types="nwr", timeout=500) %>%
add_osm_features(features=objects_osm, value_exact=TRUE) %>%
add_osm_feature(key=c("name", "!name:ca")) With your proposal, @Mashin6, the code above would require much more verbose code and, in current main, is not possible (would require the bonus from jmaspons@8736310 , using paste_features to parse the features list also in A better solution should include different functions or a function with different parameters for AND and OR additions |
It's certainly an interesting use case. I don't know how often users run queries that involve adding the same set of filters to all statements. Personally would try to approach it with lapply or for loop, but having a shorthand function that does that seem like a good idea. |
@Mashin6 raised valid concerns in #252, supported by @stragu, that the current design in counter-intuitive:
OR
AND
This needs to be improved, for which suggestions are requested!
The text was updated successfully, but these errors were encountered: