Make SpatialLines object from two SpatialPoints objects

Share:

Description

The primary conceived usage of this is to draw arrows following the trajectories of agents.

Usage

1
2
3
4
makeLines(from, to)

## S4 method for signature 'SpatialPoints,SpatialPoints'
makeLines(from, to)

Arguments

from

Starting spatial coordinates (SpatialPointsDataFrame).

to

Ending spatial coordinates (SpatialPointsDataFrame).

Value

A SpatialLines object. When this object is used within a Plot call and the length argument is specified, then arrow heads will be drawn. See examples.

Author(s)

Eliot McIntire

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library(sp)
# Make 2 objects
caribou1 <- SpatialPoints(cbind(x = stats::runif(10, -50, 50), y = stats::runif(10, -50, 50)))
caribou2 <- SpatialPoints(cbind(x = stats::runif(10, -50, 50), y = stats::runif(10, -50, 50)))

caribouTraj <- makeLines(caribou1, caribou2)
  if (interactive()) {
    clearPlot()
    Plot(caribouTraj, length = 0.1)
  }

# or  to a previous Plot
## Not run: 
filelist <- data.frame(files =
     dir(file.path(find.package("SpaDES", quiet = FALSE), "maps"),
         full.names = TRUE, pattern = "tif"),
     functions = "rasterToMemory",
     packages = "SpaDES")

# Load files to memory (using rasterToMemory)
sim1 <- loadFiles(filelist = filelist)
caribouTraj <- makeLines(caribou1, caribou2)

  if (interactive()) {
    clearPlot()
    Plot(sim1$DEM)
    Plot(caribouTraj, addTo = "sim1$DEM", length = 0.1)
  }

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.