SpaDES (version 1.1.4)

wrap: Wrap coordinates or pixels in a torus-like fashion

Description

Generally for model development purposes.

Usage

wrap(X, bounds, withHeading)

## S3 method for class 'matrix,Extent,missing': wrap(X, bounds)

## S3 method for class 'SpatialPoints,ANY,missing': wrap(X, bounds)

## S3 method for class 'matrix,Raster,missing': wrap(X, bounds)

## S3 method for class 'matrix,Raster,missing': wrap(X, bounds)

## S3 method for class 'matrix,matrix,missing': wrap(X, bounds)

## S3 method for class 'SpatialPointsDataFrame,Extent,logical': wrap(X, bounds, withHeading)

## S3 method for class 'SpatialPointsDataFrame,Raster,logical': wrap(X, bounds, withHeading)

## S3 method for class 'SpatialPointsDataFrame,matrix,logical': wrap(X, bounds, withHeading)

Arguments

X
A SpatialPoints* object, or matrix of coordinates
bounds
Either a Raster*, Extent, or bbox object defining bounds to wrap around
withHeading
logical. If TRUE, then the previous points must be wrapped also so that the subsequent heading calculation will work. Default FALSE. See details.

Value

  • Same class as X, but with coordinates updated to reflect the wrapping

Details

If withHeading used, then X must be a SpatialPointsDataFrame that contains two columns, x1 and y1, with the immediately previous agent locations.

Examples

Run this code
library(raster)
xrange <- yrange <- c(-50, 50)
hab <- raster(extent(c(xrange, yrange)))
hab[] <- 0

# initialize caribou agents
N <- 10

# previous points
x1 <- rep(0, N)
y1 <- rep(0, N)
# initial points
starts <- cbind(x = stats::runif(N, xrange[1], xrange[2]),
                y = stats::runif(N, yrange[1], yrange[2]))

# create the caribou agent object
caribou <- SpatialPointsDataFrame(coords = starts, data = data.frame(x1, y1))


ln <- rlnorm(N, 1, 0.02) # log normal step length
sd <- 30 # could be specified globally in params

Plot(hab, zero.color = "white", new = TRUE, axes = "L")
for(i in 1:10) {
  caribou <- SpaDES::crw(agent = caribou,
                         extent = extent(hab), stepLength = ln,
                         stddev = sd, lonlat = FALSE, torus = TRUE)
  Plot(caribou, addTo = "hab", axes = TRUE)
}

Run the code above in your browser using DataLab