我已经使用 readShapePoly
读取了一个 shapefile在 maptools
包,但无法使用 readOGR
读取相同的文件.我希望有人可以帮助我阅读形状文件 readOGR
.
我下载了文件 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
我能读懂自然地球 http://www.naturalearthdata.com/ 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 和俄勒冈 shapefile 之间显然存在差异
orcounty.shp
.感谢您提供有关如何阅读的任何建议
orcounty.shp
与 readOGR
.我的问题类似于这里的问题:rgdal / readOGR - unable to read shapefile from .zip
最佳答案
尝试从文件路径中删除最后一个“/”。
readOGR(dsn = 'c:/users/mark w miller/gis_in_R/shapefile_example',
layer = 'orcounty')
关于使用 readOGR 与 readShapePoly 读取形状文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22289794/