Skip to content

Instantly share code, notes, and snippets.

@obrl-soil
Last active January 27, 2017 11:47
Show Gist options
  • Save obrl-soil/ee9904263b660bc2fb340264ca2da030 to your computer and use it in GitHub Desktop.
Save obrl-soil/ee9904263b660bc2fb340264ca2da030 to your computer and use it in GitHub Desktop.
# subset out polygons from x that intersect polygons in y
# should work for other geom types too
get_intersecting <- function(x, y) {
df <- as.data.frame(st_intersects(x, y, sparse = FALSE))
df$k <- apply(df, MARGIN = 1, FUN = function(x) ifelse(any(x) == TRUE, T, F))
x$k <- df$k
xout <- filter(x, k == TRUE)
x$k <- NULL
xout$k <- NULL
return(xout)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment