shapefile $ shp:$运算符错误原子向量-DSsim包R无效

时间:2017-09-16 11:18:21

标签: r

我正在尝试添加一个shapefile,为R中的DSsim包创建一个区域。但是我一直得到错误代码 - shapefile中的错误$ shp:$ operator对原子向量无效。任何人都可以帮助我吗?

我的代码如下:

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)

1 个答案:

答案 0 :(得分:0)

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"), ....)

是shapefile的名称,在括号中(这些括​​号)。

尝试使用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)