-
Notifications
You must be signed in to change notification settings - Fork 303
Filtering a sf object could be easier, and also prettier #1148
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
Comments
I like this concept a lot. I grepped a few recent projects and found that more than half of my A minor note: it's counterintuitive to me, but I've found that
Results are pretty close here on the small dataset:
But the timing gap grows considerably over larger datasets -- median time is ~10% better here.
When subsetting really large sf objects like US Census Block files (~11M detailed shapes), I have found nearly 20% improvements consistently. I can't explain this behavior offhand. |
@pasipasi123 that approach does not hold when ml = rbind(my_line,my_line)
nc %>% st_filter(ml)
...
Simple feature collection with 16 features and 14 fields (with 8 geometries empty)
... Two approaches currently work: nc[ml,] # which also has an op argument to control which predicate to use and nc %>% filter(lengths(st_intersects(., ml)) > 0) Am I right that your proposal is to make nc %>% st_filter(ml) with a parameter to control the predicate, defaulting to |
Yes, that's what I was after. |
OK, that would then be st_filter = function(.x, .y, .pred = st_intersects) {
# check that dplyr is loaded, then
filter(.x, lengths(.pred(.x, .y)) > 0)
}
nc %>% st_filter(ml) |
@sheffe I think there is a substantial difference: when |
I had a similar problem as in this SO question and I started thinking that maybe
sf
could use a filtering function, eg.st_filter()
.Since the default error message for when one or both objects are not
sf
objects is that the crs's don't match, I've also added a more informative error message.The default method is
st_intersects
but one can specify another by using eg,st_filter(x, y, st_crosses)
.What do you think?
Created on 2019-09-12 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: