在RStudio中打开SHP文件
我有一个包含五个文件的包,其中包含所有法国管理限制(可用)。 所有这五个文件LIMITE_department.SHP/DBF/AVL/PRJ/SHX都位于/home/jonathan/R文件夹中 我使用以下代码:在RStudio中打开SHP文件,r,shapefile,maptools,R,Shapefile,Maptools,我有一个包含五个文件的包,其中包含所有法国管理限制(可用)。 所有这五个文件LIMITE_department.SHP/DBF/AVL/PRJ/SHX都位于/home/jonathan/R文件夹中 我使用以下代码: library(maptools) setwd('/home/jonathan/R') france<-readShapeSpatial("LIMITE_DEPARTEMENT", proj4string=CRS("+proj=longlat")) 我在R(3.0.1)和Rs
library(maptools)
setwd('/home/jonathan/R')
france<-readShapeSpatial("LIMITE_DEPARTEMENT", proj4string=CRS("+proj=longlat"))
我在R(3.0.1)和Rstudio(0.97.551)中进行了尝试。
我也读过这个和这个。但是,现在我不知道我能做什么
感谢您的帮助。也许您必须打开外部软件包才能读取.dbf文件。请查看
rgdal
附带的readOGR(dsn=“/path/to/data”,layer=“LIMITE_department”…)
。它通常与.dbf文件没有问题。该错误与以下事实有关: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
require(rgdal)
file.copy(from=“/tmp/LIMITE_department.DBF”,
to=“/tmp/LIMITE_department.dbf”)
删除(“/tmp/LIMITE_department.DBF”)
出发我也以R开头(法语…),我有一个类似的问题,与你得到的信息相同。我发现了一个解决方案:我刚刚插入了.shp文件的精确方式。例如,使用my Mac:/Applications/R/department/department.SHP。
已从IGN网站(国家地理学会)下载了《2014年地理平面汇编》(包含文件'department.SHP')。第一次,我将“SHP”改为“SHP”(并在R控制台中这样写:“department.SHP”):没有结果。第二次,我认为是指文件的完整路径:和成功
我使用了“maps”和“maptools”扩展(带有“sp”等)
请试一试,然后回答我 外国包裹现在被打开了。。。没有什么变化。我也试过«弗朗西试过Shapegrr。。。这里发生了什么事?如果我重命名“shape.shp”和“shape.dbf”中的文件,错误会变成“打开shp文件时出错”。//你用其他的包裹吗?sp/gripd/lattice/gpclib?实际上没有。。我已经安装了sp和maptools。宾果!它是如此简单。。。(和狡猾的)谢谢,谢谢,谢谢…:)
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