我使用maptools
包中的readShapePoly
函数读取了一个shapefile文件,但无法使用readOGR
函数读取同一文件。我希望有人能帮助我使用readOGR
函数读取这个shapefile文件。
我从这里下载了文件orcounty.shp
:http://geography.uoregon.edu/geogr/topics/maps.htm
我还下载了相关文件:orcounty.shx
、orcounty.sbx
、orcounty.sbn
和orcounty.dbf
,并将这五个文件放在文件夹中:c:/users/mark w miller/gis_in_R/shapefile_example/
以下代码读取该shapefile文件并显示一些属性:
library(maptools)
setwd('c:/users/mark w miller/gis_in_R/shapefile_example/')
# Oregon county census data (polygons)
orcounty.poly <- readShapePoly('orcounty.shp', proj4string=CRS("+proj=longlat"))
orcounty.line <- readShapeLines('orcounty.shp', proj4string=CRS("+proj=longlat"))
# see projection
summary(orcounty.poly)
Object of class SpatialPolygonsDataFrame
Coordinates:
min max
x -124.55840 -116.46944
y 41.98779 46.23626
Is projected: FALSE
proj4string : [+proj=longlat]
Data attributes:
然而,当我尝试使用以下代码读取相同的shapefile时,我收到了一个错误:
library(rgdal)
# read shapefile
oregon.map <- readOGR(dsn="c:/users/mark w miller/gis_in_R/shapefile_example/", layer="orcounty")
# convert to dataframe
oregon.map_df <- fortify(oregon.map)
错误信息显示:
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv) :
Cannot open file
我可以使用以下方式读取Natural Earth的shapefiles:
library(rgdal)
setwd("c:/users/mark w miller/gis_in_R/")
# read shapefile
wmap <- readOGR(dsn="ne_110m_physical", layer="ne_110m_land")
所以,显然自然地球的shapefile和Oregon的shapefile orcounty.shp
之间存在差异。
感谢任何有关如何使用readOGR
读取orcounty.shp
的建议。我的问题类似于这里的问题:rgdal / readOGR - 无法从.zip文件中读取shapefile
readOGR(dsn = 'c:/users/mark w miller/gis_in_R/shapefile_example', layer = 'orcounty')
。 - Paulo E. Cardoso