Skip to content
Prev 4674 / 29559 Next

kriging: export to grid

On Sun, 14 Dec 2008, Nicolas Meurisse wrote:

            
library(sp)
pred.grid$var3 <- 1
coordinates(pred.grid) <- c("Var1", "Var2")
gridded(pred.grid) <- TRUE

# Create a SpatialPixelsDataFrame or SpatialGridDataFrame object first
# - forced here by including a non-coordnate column to the data frame
myPred = krige.conv(myGData, loc = coordinates(pred.grid),
  krige = krige.control(obj.m = myOLSMod))

# Krige with the coordinates of the object

pred.grid$predict <- myPred$predict

# add the predictions (and standard errors if you like) to the
# object, they are in the correct order;
# then write out, choosing the output column as desired

tf <- tempfile()
writeGDAL(pred.grid["predict"], tf, drivername="GTiff") # not type="Byte"!
GDALinfo(tf)

# I suppose you are using the temporary file here to test your approach
# as you ought to put the output file in a permanent place if you will
# need it later

Hope this helps,

Roger