Description Usage Arguments Value See Also Examples
Given a SpatialPointsDataFrame object batch with Admin, GAUL and Date columns and a named list of covariate file paths extract the values of covariates.
1  | extractBatch(batch, covariates, factor, admin, admin_mode="average", load_stack=stack)
 | 
batch | 
 A   | 
covariates | 
 A named list of containing   | 
factor | 
 A named list stating whether each entry in   | 
admin | 
 A   | 
admin_mode | 
 A string indicating the type of extraction to perform for polygon occurrences. Acceptable values are: "average" (returns the mean value for non-discrete covariates, and the mode for discrete covariates), "random" (returns the value of a random pixel) and "latlong" (returns the value at the lat/long in the   | 
load_stack | 
 (Optional) A function which creates a stack from list of file paths. This can be used to override the crs and/or extent read from the files. Default is   | 
A matrix giving the covariate values for each of the points/admins in batch.
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53  | # load occurrence data, admin units and covariates
# normally these would be individual geotiffs on disk
data(covariates)
layers <- list(
  "cov1"=raster(covariates, layer="cov_a"),
  "cov2"=raster(covariates, layer="cov_b"),
  "cov3"=list(
    "2012"=raster(covariates, layer="cov_a"),
    "2013"=raster(covariates, layer="cov_b"),
    "2014"=raster(covariates, layer="cov_c")
  ),
  "cov4"=list(
    "2012"=raster(covariates, layer="cov_c"),
    "2013"=raster(covariates, layer="cov_b"),
    "2014"=raster(covariates, layer="cov_a")
  ),
  "cov5"=list(
    "2012-01"=raster(covariates, layer="cov_a"),
    "2012-02"=raster(covariates, layer="cov_b"),
    "2012-03"=raster(covariates, layer="cov_c")
  ),
  "cov6"=list(
    "2012-01"=raster(covariates, layer="cov_a"),
    "2012-02"=raster(covariates, layer="cov_b"),
    "2012-03"=raster(covariates, layer="cov_c")
  )
)
factor <- list(
  "cov1"=FALSE,
  "cov2"=TRUE,
  "cov3"=FALSE, 
  "cov4"=TRUE,
  "cov5"=FALSE,
  "cov6"=TRUE
)
data(admin)
data(occurrence)
occurrence <- occurrence2SPDF(occurrence)
occurrence <- getGAUL(occurrence, admin)
occurrence$Date <- as.Date(sample(c(
  "2011-10-01", 
  "2012-01-02", 
  "2012-02-02", 
  "2012-03-06", 
  "2012-04-06",
  "2015-03-06"), length(occurrence), replace=TRUE))
occurrence$PA <- sample(c(0, 1), length(occurrence), replace=TRUE)
# extract all covariates,
vals <- extractBatch(occurrence, layers, factor, admin, admin_mode="average")
head(vals)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.