diff --git a/NAMESPACE b/NAMESPACE index 59bd8ca..6f9e87d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,7 @@ export(cumPoolsCreateAGB) export(cumPoolsSmooth) export(distMatch) export(extractToRast) +export(gcLocatorCreate) export(gcidsCreate) export(m3ToBiomPlots) export(nmfac) diff --git a/R/Boudewyn_cumPoolsCreate.R b/R/Boudewyn_cumPoolsCreate.R index d0101f9..5206151 100644 --- a/R/Boudewyn_cumPoolsCreate.R +++ b/R/Boudewyn_cumPoolsCreate.R @@ -1,14 +1,14 @@ #' Create `cumPools` data.table #' -#' @param fullSpecies DESCRIPTION NEEDED -#' @param gcMeta DESCRIPTION NEEDED -#' @param userGcM3 DESCRIPTION NEEDED -#' @param stable3 DESCRIPTION NEEDED -#' @param stable4 DESCRIPTION NEEDED -#' @param stable5 DESCRIPTION NEEDED -#' @param stable6 DESCRIPTION NEEDED -#' @param stable7 DESCRIPTION NEEDED -#' @param thisAdmin DESCRIPTION NEEDED +#' @param fullSpecies Species names found in study area. +#' @param gcMeta Growth curve metadata table that links species with additional attributes. +#' @param userGcM3 Growth curve metadata table that links species with additional attributes. +#' @param stable3 Boudewyn table 3 subset to study area attributes. +#' @param stable4 Boudewyn table 3 subset to study area attributes. +#' @param stable5 Boudewyn table 3 subset to study area attributes. +#' @param stable6 Boudewyn table 3 subset to study area attributes. +#' @param stable7 Boudewyn table 3 subset to study area attributes. +#' @param thisAdmin Study area metadata #' #' @return `cumPools` data.table #' diff --git a/R/CBM-tools_gcLocatorCreate.R b/R/CBM-tools_gcLocatorCreate.R new file mode 100644 index 0000000..0307d8a --- /dev/null +++ b/R/CBM-tools_gcLocatorCreate.R @@ -0,0 +1,43 @@ +#' Create gcLocator raster layer +#' +#' Builds the gcLocator raster from site productivity, spatial unit, and leading species matched to +#' a growth curve lookup table +#' +#' @param siteProductivity Productivity class raster layer +#' @param spuRaster spatial unit ID raster layer +#' @param leadSpecies leading species raster layer +#' @param gcidLookup Table with metadata for each gcid +#' +#' +#' @return `gcLocator` SpatRaster +#' +#' @export +#' @importFrom data.table data.table as.data.table +#' @importFrom terra rast +gcLocatorCreate <- function(siteProductivity, spuRaster, leadSpecies, gcidLookup) { + + #check if all rasters share the same CRS + if (!length(unique(lapply(list(siteProductivity, spuRaster, leadSpecies), crs))) == 1){ + stop("Rasters do not all share the same CRS.") + } + + #build gcTable from the raster layers + combine <- c(leadSpecies, spuRaster, siteProductivity) + gcTable <- as.data.table(combine, na.rm = FALSE) + setnames(gcTable, c("speciesID", "spatialunit", "prodclass")) + gcTable[, cell := 1:.N] + + #merge gcTable with gcidLookup to get growth curve information for each pixel + gcTable <- merge(gcTable, gcidLookup, by = c("speciesId", "spatialunit", "prodclass"), all.x = TRUE) + colstokeep <- c("cell", "growthcurveid") + gcTable <- gcTable[, ..colstokeep] + setnames(gcTable, c("cell", "growthcurveid")) + + #build the gcLocator raster layer + gcLocator <- rast(leadSpecies) + values(gcLocator) <- NA + values(gcLocator)[gcTable$cell] <- gcTable$growthcurveid + + return(gcLocator) + +} diff --git a/man/cumPoolsCreate.Rd b/man/cumPoolsCreate.Rd index c9d969a..d7c0b70 100644 --- a/man/cumPoolsCreate.Rd +++ b/man/cumPoolsCreate.Rd @@ -17,23 +17,23 @@ cumPoolsCreate( ) } \arguments{ -\item{fullSpecies}{DESCRIPTION NEEDED} +\item{fullSpecies}{Species names found in study area.} -\item{gcMeta}{DESCRIPTION NEEDED} +\item{gcMeta}{Growth curve metadata table that links species with additional attributes.} -\item{userGcM3}{DESCRIPTION NEEDED} +\item{userGcM3}{Growth curve metadata table that links species with additional attributes.} -\item{stable3}{DESCRIPTION NEEDED} +\item{stable3}{Boudewyn table 3 subset to study area attributes.} -\item{stable4}{DESCRIPTION NEEDED} +\item{stable4}{Boudewyn table 3 subset to study area attributes.} -\item{stable5}{DESCRIPTION NEEDED} +\item{stable5}{Boudewyn table 3 subset to study area attributes.} -\item{stable6}{DESCRIPTION NEEDED} +\item{stable6}{Boudewyn table 3 subset to study area attributes.} -\item{stable7}{DESCRIPTION NEEDED} +\item{stable7}{Boudewyn table 3 subset to study area attributes.} -\item{thisAdmin}{DESCRIPTION NEEDED} +\item{thisAdmin}{Study area metadata} } \value{ \code{cumPools} data.table diff --git a/man/gcLocatorCreate.Rd b/man/gcLocatorCreate.Rd new file mode 100644 index 0000000..0803379 --- /dev/null +++ b/man/gcLocatorCreate.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CBM-tools_gcLocatorCreate.R +\name{gcLocatorCreate} +\alias{gcLocatorCreate} +\title{Create gcLocator raster layer} +\usage{ +gcLocatorCreate(siteProductivity, spuRaster, leadSpecies, gcidLookup) +} +\arguments{ +\item{siteProductivity}{Productivity class raster layer} + +\item{spuRaster}{spatial unit ID raster layer} + +\item{leadSpecies}{leading species raster layer} + +\item{gcidLookup}{Table with metadata for each gcid} +} +\value{ +\code{gcLocator} SpatRaster +} +\description{ +Builds the gcLocator raster from site productivity, spatial unit, and leading species matched to +a growth curve lookup table +}