1

I am trying to do universal cokriging in R with the Gstat package. I have a script that i was helped with, but now i'm stuck and can't ask assistance from the original source. The problem is that i can't change the output resolution of the cokriged data. I would like to import the interpolated map to ArcMap and point-to-raster leaves me with a very low resolution.

My script is as follows:

  library(raster)
library(gstat)
library(sp)
library(rgdal)
library(FitAR)

Loading my dataset, that containes coordinates and sampled values:

kova<-read.table("katvus_point_modif3.txt",sep="    ",header=T)
coordinates(kova)=~POINT_X+POINT_Y

Loading depth values at the same coordinates as the previous, this is my covariate:

Sygavus<-read.table("sygavus_point_cokrig.txt",sep="    ",header=T)
coordinates(Sygavus)=~POINT_X+POINT_Y

overlay <- over(kova,Sygavus)
kova$Sygavus <- overlay$Sygavus

This is supposed to set the boundary for my interpolation, the file is an exported shapefile from ArcMap:

border <- shapefile("area_2014.shp")
projection(kova)=projection(border)

This is supposed to create a grid for cokriging and the res= should let me specify what resolution i want the output to be, but no matter what number i use the output does not change.

grid <- spsample(border,type="regular",res=25)

I remove overlaping points:

zero <- zerodist(kova)
kova <- kova[-zero[,2],]              

I load in the depth covariate raster-file. This is a depth raster export from ArcMap to ascii form:

depth <- raster("htp_depth_covar.asc")
projection(depth)=projection(border)

overlay <- extract(depth,kova)
kova$depth <- overlay

I remove na! values from the overlain depth values (These values should be the same as the previously loaded depth covariate table at the respective coordinates, but if i leave that part out, the script stops functioning)

kova <- kova[!is.na(kova$depth),]


kova.gstat <- gstat(id="Kova",formula=kova~depth,data=kova)
kova.gstat <- gstat(kova.gstat,id="Sygavus",formula=Sygavus~depth,data=kova)

var.kova <- variogram(kova.gstat)
plot(var.kova)

kova.gstat <- gstat(kova.gstat,id=c("Kova","Sygavus"),model=vgm(psill=cov(kova$kova,kova$Sygavus),model="Mat",range=12000,nugget=0))
kova.gstat <- fit.lmc(var.kova,kova.gstat,model=vgm(psill=cov(kova$kova,kova$Sygavus),model="Mat",range=12000,nugget=0))

plot(var.kova,kova.gstat$model)

overlay <- extract(depth,grid)
grid <- as.data.frame(grid)
grid$depth <- overlay
coordinates(grid)=~x1+x2
projection(grid)=projection(border)

krige <- predict.gstat(kova.gstat,grid)

spplot(krige,c("Kova.pred"))

write.table(krige, "kova.raster1.ck.csv", sep=";", dec=",", row.names=F)

Any help in understanding the gstat cokriging and the script overall would be greatly appreciated!

Castle
  • 53
  • 6

1 Answers1

0

Because you don't provide a reproducible example I can only guess, but I think that spsample ignores the res=25 argument. Try n=1000 instead and then increase that value to get higher resolution.

Edzer Pebesma
  • 3,814
  • 16
  • 26