Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export(cumPoolsCreateAGB)
export(cumPoolsSmooth)
export(distMatch)
export(extractToRast)
export(gcLocatorCreate)
export(gcidsCreate)
export(m3ToBiomPlots)
export(nmfac)
Expand Down
18 changes: 9 additions & 9 deletions R/Boudewyn_cumPoolsCreate.R
Original file line number Diff line number Diff line change
@@ -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
#'
Expand Down
43 changes: 43 additions & 0 deletions R/CBM-tools_gcLocatorCreate.R
Original file line number Diff line number Diff line change
@@ -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)

}
18 changes: 9 additions & 9 deletions man/cumPoolsCreate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions man/gcLocatorCreate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading