Learn R Programming

GSIF (version 0.3-1)

makeGstatCmd: Make a gstat command script

Description

Generates a command script based on the regression model and variogram. This can then be used to run predictions/simulations by using the pre-compiled binary gstat.exe.

Usage

makeGstatCmd(formString, vgmModel, outfile, easfile, 
        nsim = 0, nmin = 20, nmax = 40, radius, zmap = 0, 
        predictions = "var1.pred.hdr", variances = "var1.svar.hdr", 
        xcol = 1, ycol = 2, zcol = 3, vcol = 4, Xcols)

Arguments

formString
object of class "formula" --- regression model
vgmModel
object of class "vgmmodel" or "data.frame"
outfile
character; output file for the command script
easfile
character; file name for the GeoEAS file with observed values
nsim
integer; number of simulations
nmin
integer; smallest number of points in the search radius (see gstat user's manual)
nmax
integer; largest number of points in the search radius (see gstat user's manual)
radius
numeric; search radius (see gstat user's manual)
zmap
numeric; fixed value for the 3D dimension in the case of 3D kriging
predictions
character; output file name for predictions
variances
character; output file name for kriging variances
xcol
integer; position of the x column in the GeoEAS file
ycol
integer; position of the y column in the GeoEAS file
zcol
integer; position of the z column in the GeoEAS file
vcol
integer; position of the target variable column in the GeoEAS file
Xcols
integer; column numbers for the list of covariates

encoding

latin1

Details

To run the script under Windows OS you need to obtain the pre-compiled gstat.exe program from the www.gstat.org website, and put it in some directory e.g. c:/gstat/. Then add the program to your path (see environmental variable under Windows > Control panel > System > Advanced > Environmental variables), or copy the exe program directly to some windows system directory.

References

  • Bivand, R.S., Pebesma, E.J., andG�mez{Gomez}-Rubio, V., (2008)http://www.asdar-book.org/{Applied Spatial Data Analysis with R}. Springer, 378 p.
  • Pebesma, E., (2003)http://www.gstat.org/gstat.pdf{Gstat user's manual}. Dept. of Physical Geography, Utrecht University, p. 100, www.gstat.org

See Also

write.data, fit.gstatModel, gstat::krige

Examples

Run this code
library(sp)

# Meuse data:
loadMeuse()
# fit a model:
omm <- fit.gstatModel(observations = meuse, formulaString = om~dist, 
  family = gaussian(log), covariates = meuse.grid)
str(omm@vgmModel)
# write the regression matrix to GeoEAS:
meuse$log_om <- log1p(meuse$om)
write.data(obj=meuse, covariates=meuse.grid["dist"], 
    outfile="meuse.eas", methodid="log_om")
writeGDAL(meuse.grid["dist"], "dist.rst", drivername="RST", mvFlag="-99999")
makeGstatCmd(log_om~dist, vgmModel=omm@vgmModel, 
    outfile="meuse_om_sims.cmd", easfile="meuse.eas", 
    nsim=50, nmin=20, nmax=40, radius=1500)
# compare the processing times:
system.time(system("gstat meuse_om_sims.cmd"))
vgmModel = omm@vgmModel
class(vgmModel) <- c("variogramModel", "data.frame")
system.time(om.rk <- krige(log_om~dist, meuse[!is.na(meuse$log_om),], 
    meuse.grid, nmin=20, nmax=40, model=vgmModel, nsim=50))

Run the code above in your browser using DataLab