Skip to contents

This function breaks up a LINESTRING geometries into smaller pieces.

Usage

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.

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
#> Bounding box:  xmin: -1.535849 ymin: 53.8282 xmax: -1.516748 ymax: 53.83041
#> Geodetic CRS:  WGS 84
#> LINESTRING (-1.516748 53.82868, -1.517513 53.82...
l_split
#> Geometry set for 2 features 
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -1.535849 ymin: 53.8282 xmax: -1.516748 ymax: 53.83041
#> Geodetic 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)
#> 1534.728 [m]
sum(sf::st_length(l_split))
#> 1534.728 [m]
plot(z)
plot(l, add = TRUE, lwd = 9, col = "grey")
plot(l_split, add = TRUE, col = 1:length(l_split))