line_segment: Divide an sf object with LINESTRING geometry into regular...

View source: R/linefuns.R

line_segmentR Documentation

Divide an sf object with LINESTRING geometry into regular segments

Description

This function keeps the attributes

Usage

line_segment(l, n_segments = NA, segment_length = NA)

Arguments

l

A spatial lines object

n_segments

The number of segments to divide the line into

segment_length

The approximate length of segments in the output (overides n_segments if set)

See Also

Other lines: angle_diff(), geo_toptail(), is_linepoint(), line2df(), line2points(), line_bearing(), line_breakup(), line_midpoint(), line_via(), mats2line(), n_vertices(), onewaygeo(), points2line(), toptail_buff()

Examples

l <- routes_fast_sf[2, ]
l_seg2 <- line_segment(l = l, n_segments = 2)
l_seg3 <- line_segment(l = l, n_segments = 3)
l_seg_100 <- line_segment(l = l, segment_length = 100)
l_seg_2000 <- line_segment(l = l, segment_length = 2000)
plot(sf::st_geometry(l_seg2), col = 1:2, lwd = 5)
plot(sf::st_geometry(l_seg3), col = 1:3, lwd = 5)
plot(sf::st_geometry(l_seg_100), col = seq(nrow(l_seg_100)), lwd = 5)
plot(sf::st_geometry(l_seg_2000), col = seq(nrow(l_seg_100)), lwd = 5)
# Multiple lines
l <- routes_fast_sf[2:4, ]
l_seg_multi = line_segment(l, segment_length = 1000)
plot(sf::st_geometry(l_seg_multi), col = seq(nrow(l_seg_100)), lwd = 5)

stplanr documentation built on Sept. 15, 2023, 9:07 a.m.