【问题标题】:Error in shapefile$shp : $ operator is invalid for atomic vectors- DSsim package Rshapefile$shp 中的错误:$ 运算符对原子向量无效-DSsim 包 R
【发布时间】:2017-09-16 11:18:20
【问题描述】:

在为 R 中的 DSsim 包创建区域时,我正在尝试添加 shapefile。但我不断收到错误代码 - shapefile$shp 中的错误:$ 运算符对原子向量无效。谁能帮帮我?

我的代码如下:

library(DSsim)
file.path("C:/Users/user/Desktop/Lorna/Distance/WITH VARIABLES/C3p", "C3p.shp")
C3P <- shapefiles::read.shp("C3p.shp")
region.label <- make.region(region.name = "C3P", strata.name = 0, units = "km", area = 51.02, shapefile=("C3p.shp"), check.LinkID = TRUE)

【问题讨论】:

    标签: r


    【解决方案1】:

    make.region 的帮助说:

    shapefile: a shapefile object of the region loaded into R using
              ‘read.shapefile(shape.name)’ from the shapefiles library.
    

    但你已经完成了:

    region.label <- make.region(...., shapefile=("C3p.shp"), ....)
    

    这是形状文件的名称,在括号中(这些括​​号)。

    尝试使用read.shapefiles 而不是read.shp

    C3P <- shapefiles::read.shapefile(
        "C:/Users/user/Desktop/Lorna/Distance/WITH VARIABLES/C3p"
    )
    

    假设你的 shapefile 的路径是 "C:/Users/user/Desktop/Lorna/Distance/WITH VARIABLES/C3p.shp"C3p.shx 等类似。

    然后:

    region.label <- make.region(
      region.name = "C3P",
      strata.name = 0,
      units = "km", 
      area = 51.02,
      shapefile=C3P, # the object you created two lines previous 
      check.LinkID = TRUE)
    

    【讨论】:

    • 谢谢您的帮助。我刚刚尝试了您的建议,并显示以下错误:文件中的错误(shp.name,“rb”):无法打开连接另外:警告消息:在文件中(shp.name,“rb”):不能打开文件'C3p.shp.shp':没有这样的文件或目录显然我在建立文件连接时出错了,(文件名是正确的),所以必须找到我出错的地方
    • 我不明白为什么你的代码中有一个 file.path 调用,但它什么都不做。如果那是 shapefile 所在的位置,那么您需要在 read.shapefile 调用中提供完整路径,看起来您必须省略 .shp 位。查看修改。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 2015-10-02
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    • 2021-08-20
    相关资源
    最近更新 更多