This function breaks up a LINESTRING geometries into smaller pieces.

line_breakup(l, z)

Arguments

l

An sf object with LINESTRING geometry

z

An sf object with POLYGON geometry or a number representing the resolution of grid cells used to break up the linestring objects

Value

An sf object with LINESTRING geometry created after breaking up the input object.

See also

Examples

library(sf) z <- zones_sf$geometry l <- routes_fast_sf$geometry[2] l_split <- line_breakup(l, z) l
#> Geometry set for 1 feature #> geometry type: LINESTRING #> dimension: XY #> bbox: xmin: -1.535849 ymin: 53.8282 xmax: -1.516748 ymax: 53.83041 #> geographic CRS: WGS 84
#> LINESTRING (-1.516748 53.82868, -1.517513 53.82...
l_split
#> Geometry set for 2 features #> geometry type: LINESTRING #> dimension: XY #> bbox: xmin: -1.535849 ymin: 53.8282 xmax: -1.516748 ymax: 53.83041 #> geographic CRS: WGS 84
#> LINESTRING (-1.516748 53.82868, -1.517513 53.82...
#> LINESTRING (-1.526629 53.82927, -1.526957 53.82...
sf::st_length(l)
#> 1538.881 [m]
sum(sf::st_length(l_split))
#> 1538.881 [m]
plot(z)
plot(l, add = TRUE, lwd = 9, col = "grey")
plot(l_split, add = TRUE, col = 1:length(l_split))