I have soil analysis data in an Excel spreadsheet with coordinates, and a contour shapefile. I want to create a loop function that selects the data of interest and interpolates them. I would prefer a solution using terraor a non-deprecated package. currently, I am getting an error using this code:
contorno<-vect(paste(talhao, safra,"polig.shp", sep="_"))
analise_solo<-read_excel(file.path(paste0(caminho_csv, paste(talhao,safra,"00_20.xlsx",sep="_"))),skip=0,col_names=TRUE, na=NS)
analise_solo_t <- vect(analise_solo, geom=c('Longitude', 'Latitude'), crs=crs4326, keepgeom=FALSE)
analise_solo_dta <- analise_solo_t
d <- data.frame(geom(analise_solo_dta)[,c("x", "y")], as.data.frame(analise_solo_dta))
r <- rast(contorno, res=0.00002)
(variaveis_calcario =names(d))
(variaveis_calcario =c(variaveis_calcario[46:49],variaveis_calcario[52:53]))
gs2_ <- list()
for(i in 1:length(variaveis_calcario)){
gs2_[i] <- gstat(formula=variaveis_calcario[i]~1, locations=~x+y, data=d, nmax=8, set=list(idp=2))
mapa_ <- list()
for(j in 1:length(gs2_)){
mapa_[j] <-interpolate(r, gs2_[j], debug.level=1)
}
}
Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "list" In addition: Warning message: In gs2_[i] <- gstat(formula = variaveis_calcario[i] ~ 1, locations = ~x + : number of items to replace is not a multiple of replacement length
You can do something like this: