gpt4 book ai didi

r - 在 RStudio 中打开 SHP 文件

转载 作者:行者123 更新时间:2023-12-01 01:07:45 28 4
gpt4 key购买 nike

我有一个包含所有法语管理限制的五个文件包(可用 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com