【问题标题】:autokrige and proj4stringautokrige 和 proj4string
【发布时间】:2012-08-24 14:25:37
【问题描述】:

我正在使用automap 包中的R 函数autokrige,但出现错误,我不知道如何解决。你有什么提示吗?

谢谢!

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"

【问题讨论】:

    标签: r spatial-interpolation automap


    【解决方案1】:

    以下代码重现了您的问题:

    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"
    

    问题是你使用newdata =,而你应该使用new_data =(注意下划线)。以下代码运行良好:

    kr = autoKrige(zinc~1, meuse, new_data = meuse.grid)
    

    autoKrige 的文档显示了这一点,但 krige(来自 gstat)使用 newdata,所以我理解这种混淆。

    问题是newdata = 不被autoKrige 识别,并放入参数列表的... 部分。当autoKrige 调用krige 时,autoKrige 提供的new_data... 提供的newdata 之间存在冲突。为了防止其他用户收到相当模糊的错误消息,我在 automap 中添加了一个检查。错误的代码现在会导致异常:

    > 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'.
    

    【讨论】:

    • 新版本即将上线 CRAN。
    • 是否有理由不使用被广泛接受的标准参数名称newdata 来处理这类事情?不一致对 R 的学习曲线没有帮助。
    猜你喜欢
    • 2015-05-01
    • 2019-11-15
    • 2013-07-19
    • 2014-10-09
    • 2015-12-03
    • 2014-11-28
    • 2014-08-14
    • 2021-07-15
    • 2018-01-01
    相关资源
    最近更新 更多