Replace NA values in gridded layers with a fixed value.
Source:R/spl_replaceGriddedNA.R
spl_replaceGriddedNA.Rd
This function replaces all NA values in a spatial gridded layer with
a fixed value such as for example 0
. Accepted input layers are for SpatRaster
from
the "terra"
R-package and stars
from the "stars"
R-package.
Arguments
- obj
A
SpatRaster
,SpatRasterDataset
orstars
object.- value
A fixed numeric value of which all
NA
values are to be replaced with (Default:0
).- mask
An optional
SpatRaster
object used instead of the value.- verbose
Be chatty about what is processed (Default:
FALSE
).
Details
Required inputs are a single "obj"
gridded data object and a numeric value.
In addition an optional mask layer can be provided that to use a mask. In this case
all no-data values a replaced with the value in this mask.
Examples
# Example
s <- terra::rast(system.file("ex/logo.tif", package="terra"))
s[sample(1:terra::ncell(s), 100)] <- NA
sfill <- spl_replaceGriddedNA(s, value = 100)
terra::plot(sfill)