Hello,

I can not properly transform my kriged data in a spatial data frame. I would like to have my kriged precipitation values put where my ditigal elevation model grid points are in elev.asc.

Here is my code. Would anyone have any ideas?

THANK YOU,

Cara

# mean data to be krigged
meanPrec <- read.delim("MEANPREC.txt")
names(meanPrec) <- c("X","Y","meanPrec","Z")
meanPrec.x <- meanPrec$X
meanPrec.y <- meanPrec$Y
meanPrec.z <- meanPrec$Z
str(meanPrec)
coordinates(meanPrec)=~X+Y+Z
str(meanPrec)

# Bring in GIS elevation as prediction base
elev <- read.asciigrid("elev.asc", as.image=FALSE, plot.image=TRUE)
Formal class 'SpatialGridDataFrame' [package "sp"] with 6 slots
  ..@ data       :'data.frame': 1157478 obs. of  1 variable:
  .. ..$ elev.asc: num [1:1157478] NA NA NA NA NA NA NA NA NA NA ...
  ..@ grid       :Formal class 'GridTopology' [package "sp"] with 3 slots
  .. .. ..@ cellcentre.offset: num [1:2] 549663 78563
  .. .. ..@ cellsize         : num [1:2] 100 100
  .. .. ..@ cells.dim        : int [1:2] 1302 889
  ..@ grid.index : int(0)
  ..@ coords     : num [1:2, 1:2] 549663 679763 78563 167363
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
  ..@ bbox       : num [1:2, 1:2] 549613 78513 679813 167413
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "coords.x1" "coords.x2"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
  .. .. ..@ projargs: chr NA

elev <- as.data.frame(elev)
names(elev) <- c("Z","X","Y")
elev.x <- elev$X
elev.y <- elev$Y
elev.z <- elev$Z
coordinates(elev) <- ~X+Y+Z
str(elev)

# universal kriging with meanPrec with elevation trend
elev_ked <- krige(meanPrec~Z, meanPrec, newdata=elev, fitted_vario)

# write grid to ascii file, must have SpatialGridDataFrame
elevgrid <- GridTopology(c(549663,78563), c(100,100), c(1302,889)) ##original elev.asc information
data <- elev_ked ## data retured from kriging, both prediction and variance
## trying to create spatial grid data frame, but failing
elevgridnew <- SpatialGridDataFrame(elevgrid, data, proj4string = CRS(as.character(NA)))
write.asciigrid(elev_ked[1], "elev_ked.asc")

	[[alternative HTML version deleted]]

