#' Synchronise NA cells across layers in a RasterStack.
#'
#' If any layer within a rasterstack contains a missing value (NA), all layers will be set to NA for that cell across the entire rasterstack.
#' This function is useful when combining data products from different sources which may have slight mismatches in available data along coastlines, for example.
#'
#' @param stack RasterStack object to be processed
#' @return Returns a rasterstack object.
#' @export
#' @examples Coming soon.
sync_na <- function(stack)
{
if(canProcessInMemory(stack, n = 2))
{
val <- getValues(stack)
NA.pos <- unique(which(is.na(val), arr.ind = T)[, 1])
val[NA.pos, ] <- NA
x <- setValues(stack, val)
return(x)
} else
{
x <- mask(stack, calc(stack, fun = sum))
return(x)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.