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

Description Usage Arguments Details Value Author(s) Examples

Description

Generally for model development purposes.

Usage

 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
wrap(X, bounds, withHeading)

## S4 method for signature 'matrix,Extent,missing'
wrap(X, bounds)

## S4 method for signature 'SpatialPoints,ANY,missing'
wrap(X, bounds)

## S4 method for signature 'matrix,Raster,missing'
wrap(X, bounds)

## S4 method for signature 'matrix,Raster,missing'
wrap(X, bounds)

## S4 method for signature 'matrix,matrix,missing'
wrap(X, bounds)

## S4 method for signature 'SpatialPointsDataFrame,Extent,logical'
wrap(X, bounds, withHeading)

## S4 method for signature 'SpatialPointsDataFrame,Raster,logical'
wrap(X, bounds, withHeading)

## S4 method for signature '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.

Details

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

Value

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

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
31
32
library(raster)
xrange <- yrange <- c(-50, 50)
hab <- raster(extent(c(xrange, yrange)))
hab[] <- 0

# initialize 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 agent object
agent <- 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

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


Search within the SpaDES package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.