fillNAs,GRaster-method | R Documentation |
This function uses splines to fill NA
cells in a raster based on the values of nearby cells. Depending on the method used, not all NA
cells can be filled.
## S4 method for signature 'GRaster'
fillNAs(
x,
lambda = NULL,
method = "bilinear",
min = -Inf,
max = Inf,
cells = Inf
)
x |
A |
lambda |
Either |
method |
Character: Type of spline, either " Note: The RST method will often display warnings, but these can be ignored. |
min , max |
Numeric: Lowest and highest values allowed in the interpolated values. Values outside these bounds will be truncated to the minimum/maximum value(s) allowed. The default imposes no constraints. For multi-layered rasters, you can supply a single value for |
cells |
Integer or numeric integer: Number of cells away from the non- |
A GRaster
.
terra::interpNear()
, GRASS module r.fillnulls
(see grassHelp("r.fillnulls")
)
if (grassStarted()) {
# Setup
library(terra)
# Elevation raster:
madElev <- fastData("madElev")
# Convert a SpatRaster to a GRaster:
elev <- fast(madElev)
### Fill NAs:
bilinear <- fillNAs(elev)
bicubic <- fillNAs(elev, method = "bicubic")
rst <- fillNAs(elev, method = "rst")
maps <- c(elev, bilinear, bicubic, rst)
names(maps) <- c("original", "bilinear", "bicubic", "RST")
plot(maps)
### Constrain interpolated values to > 0
constrained <- fillNAs(elev, min = 0)
# Compare unconstrained and constrained:
minmax(bilinear)
minmax(constrained)
### Interpolate to only first 10 cells away from non-NA cells:
restrained <- fillNAs(elev, cells = 10)
maps <- c(elev, restrained)
names(maps) <- c("Original", "within 10 cells")
plot(maps)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.