View source: R/mkdeFunctions.R
mkdeToTerra | R Documentation |
Converts an MKDE into a RasterLayer or RasterStack so that raster package functions can be used.
mkdeToTerra(mkde.obj)
mkde.obj |
A 2D, 2.5D, or 3D MKDE object created with
|
This method converts the density array in the MKDE oject to an object of a class from the raster package. This allows the functions in the raster package to be used with the MKDEs.
If the MKDE is 2D or 2.5D, a RasterLayer object is returned. If the MKDE is 3D, a RasterStack is returned with one layer in the stack per level.
Jeff A. Tracey, PhD
USGS Western Ecological Research Center, San Diego Field Station
jatracey@usgs.gov
James Sheppard, PhD
San Diego Zoo Institute for Conservation Research
jsheppard@sandiegozoo.org
library(terra)
# set up MKDE object
fpath <- system.file("extdata", "pandadem.RDS", package="mkde")
pandadem <- terra::readRDS(fpath)
cell.sz <- mean(res(pandadem))
ext <- ext(pandadem)
nx <- ncol(pandadem)
ny <- nrow(pandadem)
mkde.obj <- initializeMKDE2D(ext$xmin, cell.sz, nx, ext$ymin, cell.sz, ny)
# set up movement data
data(panda)
mv.dat <- initializeMovementData(panda$time, panda$x, panda$y,
sig2obs=25.0, t.max=185.0)
# estimate density
dens.res <- initializeDensity(mkde.obj, mv.dat)
mkde.obj <- dens.res$mkde.obj
mv.dat <- dens.res$move.dat
mkde.rst <- mkdeToTerra(mkde.obj)
plot(mkde.rst)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.