This will convert 2 objects whose coordinates can be extracted with coordinates (e.g., sp::SpatialPoints*) to a single SpatialLines object. The first object is treated as the "to" (destination), and the second object the "from" (source). This can be used to represent directional SpatialLines, especially with with arrow heads, as in Plot(sl, length = 0.1).

sp2sl(sp1, from)

Arguments

sp1

a SpatialPoints* object

from

a SpatialPoints* object. Optional. If not provided, then the function will attempt to find the "previous" coordinates as columns (prevX, prevY) in the sp1 object.

Examples

caribou <- terra::vect(x = cbind(x = stats::runif(1e1, -50, 50),
                                        y = stats::runif(1e1, -50, 50)))
caribouFrom <- terra::vect(x = cbind(x = stats::runif(1e1, -50, 50),
                                        y = stats::runif(1e1, -50, 50)))
caribouLines <- sp2sl(caribou, caribouFrom)
if (interactive()) {
  clearPlot()
  Plot(caribouLines, length = 0.1)
}