extractBatch: Extract a batch of occurrence data. Takes account of synoptic...

Description Usage Arguments Value See Also Examples

View source: R/seegSDM.R

Description

Given a SpatialPointsDataFrame object batch with Admin, GAUL and Date columns and a named list of covariate file paths extract the values of covariates.

Usage

1
extractBatch(batch, covariates, factor, admin, admin_mode="average", load_stack=stack)

Arguments

batch

A SpatialPointsDataFrame of occurrence records containing at least a column named Admin giving the admin level of the occurrence (an integer from 0 to 3, or -999 for point data), a column named GAUL giving the GAUL codes for polygons occurrences and a column named Date giving the occurrence date of the occurrence as a Date object.

covariates

A named list of containing RasterLayer objects (or file paths), or sublists of RasterLayer (or file paths) for temporally resolved covariates. Synoptic covariates should have an entry with an approriate name and the RasterLayer (or file paths) as it's value. Annually resolved covariates should have an entry with an approriate name and a sub-list of files as it's value. The sub-list should name names in the format "YYYY", and values which are the RasterLayer (or file paths) of each covariate layer. Monthly resolved covariates should be structured in the same way as annual covariates, but use the format "YYYY-MM". Daily resolved covariates should be structured in the same way as annual covariates, but use the format "YYYY-MM-DD".

factor

A named list stating whether each entry in covariates is discrete and should therefore be coerced into a factor.

admin

A RasterBrick or RasterStack object with four layers giving the GAUL codes for different admin levels. The layers must be in the order 0, 1, 2, 3, as they are in the example object admin.

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 SpatialPointsDataFrame, normally the centroid).

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 raster::stack.

Value

A matrix giving the covariate values for each of the points/admins in batch.

See Also

extractAdmin

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
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)

SEEG-Oxford/seegSDM documentation built on May 10, 2017, 10:25 a.m.