ropensci / stplanr

Sustainable transport planning with R
https://docs.ropensci.org/stplanr
Other
416 stars 66 forks source link

Make `line_segment()` vectorised #518

Closed Robinlovelace closed 11 months ago

Robinlovelace commented 11 months ago

Able to handle sf objects with more than 1 row, e.g. from docs:

#' 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)
Robinlovelace commented 11 months ago

Demo of this in action :tada:

https://github.com/ropensci/stplanr/assets/1825120/ab6e03ce-ef07-4145-99a4-f92f101bbc46