使用 readOGR 与 readShapePoly 读取形状文件 [英] Read shape file with readOGR verses readShapePoly

查看:35
本文介绍了使用 readOGR 与 readShapePoly 读取形状文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 maptools 包中的 readShapePoly 读取了 shapefile,但无法使用 readOGR 读取该文件.我希望有人能够帮助我使用 readOGR 阅读 shapefile.

I have read a shapefile using readShapePoly in the maptools package, but cannot read that same file with readOGR. I am hoping someone may be able to help me read the shapefile with readOGR.

我从这里下载了文件 orcounty.shp:http://geography.uoregon.edu/geogr/topics/maps.htm

I downloaded the file orcounty.shp from here: http://geography.uoregon.edu/geogr/topics/maps.htm

我还下载了相关文件:orcounty.shxorcounty.sbxorcounty.sbnorcounty.dbf 并将所有五个文件放在文件夹中:c:/users/mark w miller/gis_in_R/shapefile_example/

I also downloaded the associated files: orcounty.shx, orcounty.sbx, orcounty.sbn, and orcounty.dbf and put all five files in the folder: c:/users/mark w miller/gis_in_R/shapefile_example/

以下代码读取 shapefile 并显示一些属性:

The following code reads the shapefile and displays some attributes:

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 时,我收到一个错误:

However, when I try to read that same shapefile using the following code I receive an error:

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 http://www.naturalearthdata.com/ 形状文件:

I can read Natural Earth http://www.naturalearthdata.com/ shapefiles using:

library(rgdal)

setwd("c:/users/mark w miller/gis_in_R/")

# read shapefile
wmap <- readOGR(dsn="ne_110m_physical", layer="ne_110m_land")

因此,自然地球形状文件和俄勒冈形状文件orcounty.shp之间显然存在差异.

So, apparently there is a difference between the Natural Earth shapefiles and the Oregon shapefile orcounty.shp.

感谢您提供有关如何使用 readOGR 阅读 orcounty.shp 的任何建议.我的问题类似于这里的问题:rgdal/readOGR - 无法阅读来自 .zip 的 shapefile

Thank you for any advice on how to read orcounty.shp with readOGR. My question is similar to the question here: rgdal / readOGR - unable to read shapefile from .zip

推荐答案

尝试从文件路径中删除最后一个/".

Try to remove your last '/' from file path.

readOGR(dsn = 'c:/users/mark w miller/gis_in_R/shapefile_example',
        layer = 'orcounty')

这篇关于使用 readOGR 与 readShapePoly 读取形状文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆