I noticed that border_segment does not return the right number of segments if the input is a multilinestring. This seems to be a problem with st_cast, which can be fixed when using st_line_merge first, as shown in the MWE below:
library(sf)
library(SpatialRDD)
## Load example data
ch <- st_as_sf(raster::getData(name = "GADM", country = "CHE", level = 1))
ch <- st_transform(ch, 2056)
zh <- ch[grepl("Zür", ch$NAME_1),]
ag <- ch[grepl("Aar", ch$NAME_1),]
pts <- st_as_sf(st_sample(rbind(zh, ag), 1000))
border <- st_intersection(st_boundary(zh), st_boundary(ag))
## Use border_segment to split up into 10 segments
test <- border_segment(pts, border, 10)
## This creates 143 instead of 10 segments
length(unique(test))
## Try again with st_line_merge
test2 <- border_segment(pts, st_line_merge(border), 10)
## This creates 10 segments
length(unique(test2))
By the way this package is great!
I noticed that
border_segmentdoes not return the right number of segments if the input is a multilinestring. This seems to be a problem withst_cast, which can be fixed when usingst_line_mergefirst, as shown in the MWE below:By the way this package is great!