Skip to contents

Segment a single line, using lwgeom or rsgeo

Usage

line_segment1(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 (overrides n_segments if set)

Examples

l <- routes_fast_sf[2, ]
l_seg2 <- line_segment1(l = l, n_segments = 2)
# Test with rsgeo (must be installed):
# l_seg2_rsgeo = line_segment1(l = l, n_segments = 2)
# waldo::compare(l_seg2, l_seg2_rsgeo)
l_seg3 <- line_segment1(l = l, n_segments = 3)
l_seg_100 <- line_segment1(l = l, segment_length = 100)
l_seg_1000 <- line_segment1(l = l, segment_length = 1000)
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_1000), col = seq(nrow(l_seg_1000)), lwd = 5)