This will download all KNN layers in (Boreal) Forest of Canada, and make a factor raster at resolution provided by res (larger is faster).

speciesInStudyArea defaults to use a url of a dataset uploaded to Google Drive that is from Canadian Boreal Forests, but a different factor raster can be passed e.g., from speciesPresentFromKNN.

speciesPresentFromKNN(
  year = 2011,
  dPath = asPath("."),
  res = 2000,
  minPctCover = 10
)

speciesInStudyArea(
  studyArea,
  url = NULL,
  speciesPresentRas = NULL,
  dPath = getOption("reproducible.destinationPath")
)

Arguments

year

Default (and only implemented) is 2011. This will download the 2011 KNN data layers

dPath

Passed to destinationPath in preProcess.

res

The resolution (one dimension, in m) for the resulting raster

minPctCover

An integer indicating what percent cover a species must have in a pixel to be considered present in that pixel.

studyArea

A SpatialPolygons* object used as the principle study region, passed to reproducible::prepInputs().

url

A url to get a speciesPresence raster e.g., from peciesPresentFromKNN

speciesPresentRas

A factor raster where the character string is a string of species names, separated by 2 underscores, sorted alphabetically. Can be produced with speciesPresentFromKNN

Value

A SpatRaster object with 2 layers: "speciesPresent" is a factor, with a legend (i.e., it is numbers on a map, that correspond to a legend) and "numberSpecies" which represents the number of species in each pixel.

A named list of length 2: speciesRas is a factor RasterLayer

and speciesList is a character string containing the unique, sorted species on the speciesRas, for convenience.

Examples

if (FALSE) {
if (requireNamespace("googledrive", quietly = TRUE)) {
  # Make the dataset
  speciesPresent <- speciesPresentFromKNN(dPath = "~/data/KNN")

  # To upload this:
  speciesPresentRas <- terra::rast(speciesPresent)[[1]]
  fn <- "SpeciesPresentInCanadianForests.tif"
  writeRaster(speciesPresentRas, file = fn)
  zipFn <- gsub(".tif", ".zip", fn)
  zip(files = dir(pattern = fn), zipFn)
  out <- googledrive::drive_put(zipFn)
  driveID <- "1Oj78jJBeha5L6XDBBdWDAfimgNjYc9UD"

  # Get species list
  sa <- LandR::randomStudyArea(size = 1e11)
  species <- LandR::speciesInStudyArea(sa)
}
}