predict
instead.interpolate(object, ...)
predict(object, model, filename='', xyOnly=TRUE, ext=NULL, const=NULL, index=1, na.rm=TRUE, ...)
object
a Raster* object
model
A fitted model
filename
Output filename for a new raster; if NA the result is not written to a file but returned with the RasterLayer object, in the data slot
xyOnly
Logical. If TRUE
, values of the Raster* object are not considered as co-variables; and only x and y (longitude and latitude) are used. This should match the model
ext
An Extent object to limit the prediction to a sub-region of x
const
data.frame. Can be used to add a constant for which there is no Raster object for model predictions. Particulalry useful if the constant is a character-like factor value
index
Integer. To select the column if 'predict.model' returns a matrix with multiple columns
na.rm
Logical. Remove cells with NA values in the predictors before solving the model (and return a NA value for those cells). In most cases this will not affect the output. This option prevents errors with models that cannot handle NA values.
...
Additional arguments, see below
}
The following additional arguments can be passed, to replace default values
format
Character. Output file type. See writeRaster
datatype
Character. Output data type. See dataType
overwrite
Logical. If TRUE
, "filename" will be overwritten if it exists
progress
Character. "text", "window", or "" (the default, no progress bar)
}predict
, predict.gstat
, Tps
## Thin plate spline interpolation with x and y only
if (require(fields)) {
r <- raster(system.file("external/test.grd", package="raster"))
ra <- aggregate(r, 10)
xy <- data.frame(xyFromCell(ra, 1:ncell(ra)))
v <- getValues(ra)
tps <- Tps(xy, v)
p <- raster(r)
p <- interpolate(p, tps)
p <- mask(p, r)
plot(p)
}
##gstat examples
if (require(gstat)) {
## inverse distance weighted interpolation with gstat
r <- raster(system.file("external/test.grd", package="raster"))
data(meuse)
mg <- gstat(id = "zinc", formula = zinc~1, locations = ~x+y, data=meuse, nmax=7, set=list(idp = .5))
z <- interpolate(r, mg)
z <- mask(z, r)
## kriging
#coordinates(meuse) = ~x+y
#v <- variogram(log(zinc)~1, meuse)
#m <- fit.variogram(v, vgm(1, "Sph", 300, 1))
#g <- gstat(NULL, "log.zinc", log(zinc)~1, meuse, model = m)
#projection(r) <- projection(meuse)
#x <- interpolate(r, g)
}
Run the code above in your browser using DataLab