Split a linestring into multiple segments
Arguments
- linestring
A linestring object.
- split_points
A
sfc
object containing points to split the linestring.- tolerance
A numeric value representing the maximum distance allowed between the linestring and the split points. If the distance between a split point and the linestring exceeds this value, the point will not be used to split the linestring.
Examples
# Create a linestring
linestring <- create_linestring(0, -1, 0, 1, 2, 1, 2, 0, 0, 0)
# Create a set of split points
split_points <- create_points(0, 0, 1, 1, 2, 0)
# Plot the linestring and split points
plot(linestring)
plot(split_points, add = TRUE)
# Split the linestring
segments <- split_linestring(linestring, split_points)
# Plot the split linestrings
plot(segments, col = c("#E69F00", "#56B4E9", "#009E73", "#F0E442"), lwd = 2)