Geographic Information Systems Asked by DAFZ on December 6, 2020
I’m struggling with regression kriging in R. I want to interpolate the temperature of a watershed under consideration of elevation, but get always the same error when I want to perform the last step, which is the kriging.
I have two data frames, one of my 15 gauging stations with coordinates, elevation and the meteorological data for around 30 years on a daily basis, each day is one column (X1….X11642). The other data frame contains information about my watershed as point data with coordinates and elevation (as grid code in table)(6 columns, 315’226 rows).
My code looks like this:
library(sp)
library(rgdal)
library(raster)
library(leaflet)
library(mapview)
library(gstat)
d_t<-data_temperature
coordinates(d_t)= ~LONG+LAT
jh_sp<- jh_coord
coordinates(jh_sp)=~X+Y
ext_jh<-extent(jh_sp)
jh_ras<- raster(ext_jh)
jh_raster<-rasterize(jh_sp, jh_ras,jh_sp$GRID_CODE, fun='last', background=NA,
mask=FALSE, update=FALSE, updateValue='all', na.rm=TRUE)
proj4string(jh_raster)<-CRS("+init=epsg:4326")
jh_grid <- rasterToPoints(jh_raster, spatial = TRUE)
gridded(jh_grid)<- TRUE
proj4string(d_t) <- CRS("+init=epsg:4326")
stat_prj_t <- spTransform(d_t, CRSobj = CRS("+init=epsg:4326"))
lzn.vgm = variogram(log(X1)~1, stat_prj_t)
lzn.fit = fit.variogram(lzn.vgm, model = vgm(1, "Sph", 4000, 1))
#plot(lzn.vgm, lzn.fit)
lzn.kriged = krige(stat_prj_t$X1~stat_prj_t$ELEVATION , newdata=stat_prj_t, locations=jh_grid, model = lzn.fit)
#gjh <- gstat(id = "stat_prj_t", formula = stat_prj_t$X1~stat_prj_t$ELEVATION,
#data = stat_prj_t, maxdist=100, nmin=10, force=TRUE, model=lzn.fit)
#predgjh<- predict(gjh, jh_grid)
#spplot(predgjh)
When I perform:
lzn.kriged = krige(stat_prj_t$X1~stat_prj_t$ELEVATION , newdata=stat_prj_t, locations=jh_grid, model = lzn.fit)
I get following error:
Error in predict.gstat(g, newdata = newdata, block = block, nsim = nsim, :
dimensions do not match: locations 154 and data 15
When I perform:
gjh <- gstat(id = "stat_prj_t", formula = stat_prj_t$X1~stat_prj_t$ELEVATION,
data = stat_prj_t, maxdist=100, nmin=10, force=TRUE, model=lzn.fit)
predgjh<- predict(gjh, jh_grid)
I get this error:
Error in gstat.formula.predict(d$formula, newdata, na.action = na.action, :
NROW(locs) != NROW(X): this should not occur
I tried to figure out how to solve one of these problems but wasn’t successful, yet.
I already searched for answers on google and here in the forum, but non of suggestions worked for me.
How can I perform regression kriging without problems in R studio?
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP