I have a problem with autoKrig function and I try to make a reproducible example here:
library(automap)
library(raster)
library(dismo)
bio <- getData("worldclim", var="bio", res=10)
bio1 <- raster(bio, layer=1)
bio12 <- raster(bio, layer=12)
predictors <- stack(bio1, bio12)
bg <- randomPoints(bio1, 50)
data <- extract(predictors, bg)
data <- cbind(bg,data)
data <- data.frame(data)
coordinates(data)=~x+y
proj4string(data) = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
kg <- autoKrige(bio1~bio12, data, new_data=predictors)
This will result in:
Error in autoKrige(bio1 ~ bio12, data, new_data = predictors) :
Either input_data or new_data is in LongLat, please reproject.
input_data: +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
new_data: +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
I get the same error with my original data. I appreciate any help.
If you read the help file, it will tell you why it is throwing that error.
It looks like you need to project your data before calling
autoKrige
.