[R-sig-Geo] kriging: export to grid

Roger Bivand Roger.Bivand at nhh.no
Sun Dec 14 13:54:58 CET 2008


On Sun, 14 Dec 2008, Nicolas Meurisse wrote:

> Hello,
>
> After kriging with the use of the  krige.conv function, I would like to 
> export my result under the grid format. In order to view it into a GIS.
>
> It was suggested to me to use the writeGDAL function into the rgdal package. 
> However It looks like I have a problem of supported formats
> (dataset object of SpatialGridDataFrame-class or SpatialPixelsDataFrame-class 
> ) that is not the same as the one resulting from my krige.conv function 
> (kriging -class apparently)
>
> I tried several function to achieve this conversion (getRasterData, 
> SpatialGridDataFrame, SpatialPixelsDataFrame, create2GDAL, points2grid...). 
> But without any success.
>
> #my actual kriging script:
> pred.grid = expand.grid(seq(170000, 130000, l = 50), seq(190000, 160000, l = 
> 50))

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 = pred.grid, krige = krige.control(obj.m = 
> myOLSMod))

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

> image(myPred, loc = pred.grid, col = gray(seq(1, 0.1, l = 30)))
>
> #my conversion attempts
> tf <- tempfile()
> writeGDAL(myPred, tf, drivername="GTiff", type="Byte", options=NULL)
> [Erreur dans function (classes, fdef, mtable) : unable to find an inherited 
> method for function "gridded", for signature "kriging"]
>
> Thanks a lot,
>
> Nicolas
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list