I want to create multiple lines out of given points as sf objects
.
If I have a number of points as
library(sf)
pts <- st_multipoint(matrix(c(10, 10, 15, 20, 30, 30), nrow = 3, byrow = TRUE), dim = "XY")
and I am using st_cast
to create lines of them
lines <- st_cast(pts, "MULTILINESTRING")
I will always get one sf object
with multiple segments, but what I want to get is multiple lines (two in this example).
Best Answer
I think that the
sf
package need to know first how you want to create the lines from your points. I mean which pair ofPOINT
make everyLINESTRING
. In my example that was defined inside thelapply
function. Follow the reproducible and commented code below, hope that helps: