r - 在 RStudio 中打开 SHP 文件

标签 r shapefile maptools

我有一个包含所有法语管理限制的五个文件包(可用 here)。
所有这五个文件 LIMITE_DEPARTEMENT.SHP/DBF/AVL/PRJ/SHX 都在文件夹/home/jonathan/R 中。

我使用这个代码:

library(maptools)
setwd('/home/jonathan/R')
france<-readShapeSpatial("LIMITE_DEPARTEMENT", proj4string=CRS("+proj=longlat"))

这让我:
Error in read.dbf(filen1) : unable to open DBF file

我在 R (3.0.1) 和 Rstudio (0.97.551) 中尝试过。
我也读过这个 post而这个 one .但是,现在我不知道我能做什么......

谢谢你的帮助。

最佳答案

该错误与dbf文件的扩展名为.DBF有关。而不是 .dbf ,所以一种解决方法就是重命名它。

最好使用 rgdal::readOGR在 R 中读取 shapefile 的函数。

我的 /tmp 上有形状文件文件夹,因此将其更改为您的实际路径使其工作

require(rgdal)
file.copy(from = "/tmp/LIMITE_DEPARTEMENT.DBF", 
          to = "/tmp/LIMITE_DEPARTEMENT.dbf")
file.remove("/tmp/LIMITE_DEPARTEMENT.DBF")
depart <- readOGR(dsn = "/tmp", layer = "LIMITE_DEPARTEMENT")
str(depart, max.level = 2)
## Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots
##   ..@ data       :'data.frame':  330 obs. of  2 variables:
##   ..@ lines      :List of 330
##   .. .. [list output truncated]
##   ..@ bbox       : num [1:2, 1:2] 99226 6049647 1242375 7110524
##   .. ..- attr(*, "dimnames")=List of 2
##   ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots

关于r - 在 RStudio 中打开 SHP 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17323520/

相关文章:

r - 根据data.table中一列的值改变多列的值

r - 权重约束下的投资组合优化

python - 如何解析 .shp 文件?

r - 使用maptools readShapePoly在R中打开SHP文件时出错

r - 通过子集获取空的 SpatialPolygonsDataFrame?

r - 使用ggplot绘制SpatialPolygonsDataFrame

r - 如何在 R 中的条形图的 names.arg 中有多行和不同的字体大小?

r - 确定该函数中的函数名称

r - 如何将数据分箱到 shapefile 的六边形中并绘制它?

node.js - 如何在 Node.js 中迭代 shapefile