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. 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.

Usage

line_segment(l, segment_length = NA, use_rsgeo = NULL, debug_mode = FALSE)

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? If rsgeo is available, this faster implementation is used by default. If rsgeo is not available, the lwgeom 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)
round(st_length(l_seg_multi))
# 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)

ropensci/stplanr documentation built on March 15, 2024, 4:32 a.m.