【问题标题】:Error in shapefile(dataFolder, "file.shp")) : could not find function "shapefile"shapefile(dataFolder,“file.shp”))中的错误:找不到函数“shapefile”
【发布时间】:2021-10-01 03:18:32
【问题描述】:

我收到一个错误,说找不到函数“shapefile”。 我也尝试了所有可能的解决方案。 我在同一个文件夹中做了 shp、.shx 和 .dbf 文件等等,但它不起作用,请帮忙?

library(raster)
setwd("filename of the folder ")
S <-shapefile(datafolder,"file.shp"))

然后出错

shapefile(dataFolder, "file.shp")) 中的错误:找不到函数 "shapefile"

【问题讨论】:

标签: r


【解决方案1】:

我在这里展示raster::shapefile 的工作原理。

library(raster)
filename <- system.file("external/lux.shp", package="raster")
filename
#[1] "C:/soft/R/R-4.1.1/library/raster/external/lux.shp"
p <- shapefile(filename)
p
#class       : SpatialPolygonsDataFrame 
#features    : 12 
#extent      : 5.74414, 6.528252, 49.44781, 50.18162  (xmin, xmax, ymin, ymax)
#crs         : +proj=longlat +datum=WGS84 +no_defs 
#variables   : 5
#names       : ID_1,     NAME_1, ID_2,   NAME_2, AREA 
#min values  :    1,   Diekirch,    1, Capellen,   76 
#max values  :    3, Luxembourg,   12,    Wiltz,  312 
 

你的

S <-shapefile(datafolder,"file.shp"))

不是正确的 R 语法(括号不匹配)。也许你想要

S <- shapefile("file.shp")

S <- shapefile(file.path(datafolder,"file.shp"))

这种情况下不需要设置工作目录

【讨论】:

  • 谢谢你,罗伯特·希曼斯;它工作得很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-30
  • 2021-09-26
相关资源
最近更新 更多