1
#' @include RcppExports.R raptr-internal.R generics.R sim.space.R misc.R
2
NULL
3

4
#' @rdname sim.species
5
#'
6
#' @method sim.species RasterLayer
7
#'
8
#' @export
9
sim.species.RasterLayer <- function(x, n = 1,
10
                                    model = list("uniform", "normal",
11
                                                 "bimodal",
12
                                                 RandomFields::RPgauss())[[1]],
13
                                                 ...) {
14 4
  ret <- list()
15
  # generate raster layers
16 4
  if (inherits(model, "RMmodel")) {
17 0
    x <- sim.space(x, d = n, ...)
18 0
    for (i in seq_len(raster::nlayers(x)))
19 0
      ret[[i]] <- raster::setValues(x[[i]],
20 0
                                    boot::inv.logit(raster::getValues(x[[i]])))
21
  } else {
22 4
    x_coords <- raster::rasterToPoints(x)
23 4
    for (i in seq_len(n))
24 4
      ret[[i]] <- raster::setValues(x, do.call(paste0(model, "_niche"),
25 4
                                               args = list(x = x_coords[, 1],
26 4
                                                           y = x_coords[, 2])))
27
  }
28
  # return RasterStack object
29 4
  return(raster::stack(ret))
30
}
31

32
#' @rdname sim.species
33
#'
34
#' @method sim.species SpatialPolygons
35
#'
36
#' @export
37
sim.species.SpatialPolygons <- function(x, res, n = 1,
38
                                        model = list("normal", "uniform",
39
                                                     "bimodal",
40
                                                 RandomFields::RPgauss())[[1]],
41
                                                     ...) {
42 4
  sim.species.RasterLayer(x = blank.raster(x, res), n = n, model = model, ...)
43
}

Read our documentation on viewing source code .

Loading