I am using the R function autokrige
from automap
package, but I got an error and I do not know how to solve it. Do you have any hints?
Thank you!
sp.poidf <- SpatialPointsDataFrame(sp.poi,thresh.df)
proj4string(sp.poidf) <- CRS("+proj=longlat +datum=WGS84")
pro.df=spTransform(sp.poidf, CRS("+proj=merc +zone=32s +datum=WGS84"))
sp.new <- SpatialPoints(new.poi)
proj4string(sp.new) <- CRS("+proj=longlat +datum=WGS84")
pro.new <- spTransform(sp.new, CRS("+proj=merc +zone=32s +datum=WGS84"))
mykri <- autoKrige(mythresh~1,pro.df,newdata=pro.new)
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "proj4string", for signature "NULL"
The following code reproduces your problem:
require(automap)
require(rgdal)
loadMeuse()
proj4string(meuse) = CRS("+init=epsg:28992")
proj4string(meuse.grid) = CRS("+init=epsg:28992")
meuse = spTransform(meuse, CRS("+proj=merc +zone=32s +datum=WGS84"))
# Note that meuse.grid no longer is a grid due to the reprojection
meuse.grid = spTransform(meuse.grid, CRS("+proj=merc +zone=32s +datum=WGS84"))
kr = autoKrige(zinc~1, meuse, newdata = meuse.grid)
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "proj4string", for signature "NULL"
The problem is that you use newdata =
, while you should be using new_data =
(note the underscore). The following code runs fine:
kr = autoKrige(zinc~1, meuse, new_data = meuse.grid)
The documentation of autoKrige
shows this, but krige
(from gstat) uses newdata
, so I understand the confusion.
What goes wrong is that newdata =
is not recognized by autoKrige
, and put in the ...
part of the argument list. When autoKrige
calls krige
there is a conflict between new_data
supplied by autoKrige
, and newdata
supplied via ...
. To prevent other users from ending up with the rather vague error message, I added a check to automap. The erroneous code now leads to an exception:
> kr = autoKrige(zinc~1, meuse, newdata = meuse.grid)
Error in autoKrige(zinc ~ 1, meuse, newdata = meuse.grid) :
The argument name for the prediction object is not 'newdata', but 'new_data'.