library(sf)
# Setup a simple network
p1 <- st_point(c(0, 3))
p2 <- st_point(c(2, 1))
p3 <- st_point(c(3, 0))
p4 <- st_point(c(1, 4))
p5 <- st_point(c(3, 2))
p6 <- st_point(c(4, 1))
p7 <- st_point(c(4, 3))
p8 <- st_point(c(5, 3))
l1 <- st_linestring(c(p1, p2, p5))
l2 <- st_linestring(c(p2, p3))
l3 <- st_linestring(c(p4, p5))
l4 <- st_linestring(c(p5, p6))
l5 <- st_linestring(c(p5, p7))
l6 <- st_linestring(c(p7, p8))
network_edges <- st_sfc(l1, l2, l3, l4, l5, l6)
# Identify strokes in the full network with default settings
stroke(network_edges)
# Set a threshold to the angle between consecutive segments
stroke(network_edges, angle_threshold = 150)
# Identify strokes in flow mode (do not break initial edges)
stroke(network_edges, flow_mode = TRUE)
# Instead of returning stroke geometries, return stroke labels
stroke(network_edges, flow_mode = TRUE, attributes = TRUE)
# Identify strokes that continue one (or a subset) of edges
stroke(network_edges, from_edge = 2)
stroke(network_edges, from_edge = c(2, 3))
Run the code above in your browser using DataLab