使用 readOGR 与 readShapePoly 读取形状文件

标签 r shapefile rgdal

我已经使用 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.shpreadOGR .我的问题类似于这里的问题: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/

相关文章:

java - Geotools 解决方案读取 EPSG3035 中的 shapefile 以在 WGS84 中获取长/纬度?

r - 将纬度/经度转换为州平面坐标

r - 将索引函数应用于矩阵行中的每个值

r - 如何将arules apriori输出转换为R中的数据帧

mysql - 根据从 MYSQL 检索的 shapefile 数据在 R 中绘制多边形

R:将二进制转换为光栅文件

r - 在 Centos 上安装 rgdal 和 gdal 时遇到问题

c++ - 使用 Rcpp 时如何并行化 C++ 代码?

r - "unlist"删除列表元素中的类 (POSIXlt)

python - 在 Python/GeoPandas 中组合 shapefile