library(sf, quietly = TRUE)
library(tidygraph, quietly = TRUE)
# Create a network.
net = as_sfnetwork(roxel) %>%
st_transform(3035)
# Create a geometry to test against.
p1 = st_point(c(4151358, 3208045))
p2 = st_point(c(4151340, 3207520))
p3 = st_point(c(4151756, 3207506))
p4 = st_point(c(4151774, 3208031))
poly = st_multipoint(c(p1, p2, p3, p4)) %>%
st_cast('POLYGON') %>%
st_sfc(crs = 3035)
# Use predicate query function in a filter call.
intersects = net %>%
activate(edges) %>%
filter(edge_intersects(poly))
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1))
plot(st_geometry(net, "edges"))
plot(st_geometry(intersects, "edges"), col = "red", lwd = 2, add = TRUE)
par(oldpar)
# Use predicate query function in a mutate call.
net %>%
activate(edges) %>%
mutate(disjoint = edge_is_disjoint(poly)) %>%
select(disjoint)
Run the code above in your browser using DataLab