
Divide an sf object with LINESTRING geometry into regular segments
Source:R/linefuns.R
line_segment.Rd
This function keeps the attributes.
Note: results differ when use_rsgeo
is TRUE
:
the {rsgeo}
implementation is faster and more reliably
keeps returned linestrings below a the segment_length
value.
Arguments
- l
A spatial lines object
- segment_length
The approximate length of segments in the output (overides n_segments if set)
- use_rsgeo
Should the
rsgeo
package be used? Ifrsgeo
is available, this faster implementation is used by default. Ifrsgeo
is not available, thelwgeom
package is used.- debug_mode
Should debug messages be printed? Default is FALSE.
See also
Other lines:
angle_diff()
,
geo_toptail()
,
is_linepoint()
,
line2df()
,
line2points()
,
line_bearing()
,
line_breakup()
,
line_midpoint()
,
line_segment1()
,
line_via()
,
mats2line()
,
n_segments()
,
n_vertices()
,
onewaygeo()
,
points2line()
,
toptail_buff()
Examples
library(sf)
l <- routes_fast_sf[2:4, ]
l_seg_multi <- line_segment(l, segment_length = 1000, use_rsgeo = FALSE)
plot(l_seg_multi, col = seq_along(l_seg_multi), lwd = 5)
#> Warning: plotting the first 9 out of 16 attributes; use max.plot = 16 to plot all
#> Warning: col is not of length 1 or nrow(x): colors will be recycled; use pal to specify a color palette
#> Warning: col is not of length 1 or nrow(x): colors will be recycled; use pal to specify a color palette
#> Warning: col is not of length 1 or nrow(x): colors will be recycled; use pal to specify a color palette
#> Warning: col is not of length 1 or nrow(x): colors will be recycled; use pal to specify a color palette
#> Warning: col is not of length 1 or nrow(x): colors will be recycled; use pal to specify a color palette
#> Warning: col is not of length 1 or nrow(x): colors will be recycled; use pal to specify a color palette
#> Warning: col is not of length 1 or nrow(x): colors will be recycled; use pal to specify a color palette
#> Warning: col is not of length 1 or nrow(x): colors will be recycled; use pal to specify a color palette
#> Warning: col is not of length 1 or nrow(x): colors will be recycled; use pal to specify a color palette
round(st_length(l_seg_multi))
#> Units: [m]
#> [1] 1013 1014 955 1294 998 986 881
# Test rsgeo implementation:
# rsmulti = line_segment(l, segment_length = 1000, use_rsgeo = TRUE)
# plot(rsmulti, col = seq_along(l_seg_multi), lwd = 5)
# round(st_length(rsmulti))
# waldo::compare(l_seg_multi, rsmulti)