Create a spatial line data frame object from trajectory points.
Value
A SpatialLinesDataFrame
with one line per trajectory as specified in x.
To avoid artifacts, trajectories crossing the date line need to be split into two segments.
Where the trajectory on one side of the date line is only composed of a single point,
the trajectory won't be displayed (no line object created). The function assumes
a -180 to 180 longitudinal arrangement.
Examples
if (FALSE) { # \dontrun{
HSST <- VoCC_get_data("HSST.tif")
yrSST <- sumSeries(HSST,
p = "1969-01/2009-12", yr0 = "1955-01-01", l = terra::nlyr(HSST),
fun = function(x) colMeans(x, na.rm = TRUE), freqin = "months", freqout = "years"
)
tr <- tempTrend(yrSST, th = 10)
sg <- spatGrad(yrSST, th = 0.0001, projected = FALSE)
v <- gVoCC(tr, sg)
vel <- v[[1]]
ang <- v[[2]]
# calculate the annual SST mean over the period
mn <- terra::mean(yrSST, na.rm = TRUE)
# get the set of starting cells for the trajectories
lonlat <- stats::na.omit(data.frame(
terra::xyFromCell(vel, 1:terra::ncell(vel)),
vel[], ang[], mn[]
))[, 1:2]
# Calculate trajectories.
traj <- voccTraj(lonlat, vel, ang, mn, tyr = 50, correct = TRUE)
# create a spatial line data frame from traj
lns <- trajLine(x = traj)
terra::plot(mn)
terra::plot(lns, add = TRUE)
# Export as ESRI shape file
terra::writeVector(lns, filename = "velTraj", filetype = "ESRI Shapefile")
} # }