Learn R Programming

terra (version 0.8-5)

interpolate: Interpolate

Description

Make a RasterLayer with interpolated values using a fitted model object of classes such as "gstat" (gstat package) or "Krige" (fields package). That is, these are models that have location ("x" and "y", or "longitude" and "latitude") as independent variables. If x and y are the only independent variables provide an empty (no associated data in memory or on file) SpatRaster for which you want predictions. If there are more spatial predictor variables provide these as a Raster* object in the first argument of the function. If you do not have x and y locations as implicit predictors in your model you should use predict instead.

Usage

# S4 method for SpatRaster
interpolate(object, model, fun=predict, ..., 
       xyNames=c("x", "y"), factors=NULL, const=NULL, index = NULL, 
	   na.rm=FALSE, filename="", overwrite=FALSE, wopt=list())

Arguments

object

SpatRaster

model

model object

fun

function. Default value is "predict", but can be replaced with e.g. "predict.se" (depending on the class of the model object)

...

additional arguments passed to fun

xyNames

character. variable names that the model uses for the spatial coordinates. E.g., c("longitude", "latitude")

factors

list with levels for factor variables. The list elements should be named with names that correspond to names in object such that they can be matched. This argument may be omitted for many models as the predict function will extract the levels from the model object

const

data.frame. Can be used to add a constant for which there is no Raster object for model predictions. This is particularly useful if the constant is a character-like factor value

index

positive integer or NULL. Allows for selecting of the variable returned if the model returns multiple variables

na.rm

logical. If TRUE, cells with NA values in the predictors are removed from the computation. This option prevents errors with models that cannot handle NA values. In most other cases this will not affect the output. An exception is when predicting with a model that returns predicted values even if some (or all!) variables are NA

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

Value

SpatRaster

See Also

predict