Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用readOGR和readShapePoly读取形状文件_R_Shapefile_Rgdal - Fatal编程技术网

用readOGR和readShapePoly读取形状文件

用readOGR和readShapePoly读取形状文件,r,shapefile,rgdal,R,Shapefile,Rgdal,我使用maptools包中的readShapePoly读取了一个shapefile,但无法使用readOGR读取同一个文件。我希望有人能帮助我用readOGR阅读shapefile 我从这里下载了文件或county.shp: 我还下载了相关文件:orcounty.shx、orcounty.sbx、orcounty.sbn、以及orcounty.dbf,并将所有五个文件都放在文件夹中:c:/users/mark w miller/gis\in\u R/shapefile\u example/ 以下

我使用
maptools
包中的
readShapePoly
读取了一个shapefile,但无法使用
readOGR
读取同一个文件。我希望有人能帮助我用
readOGR
阅读shapefile

我从这里下载了文件
或county.shp

我还下载了相关文件:
orcounty.shx
orcounty.sbx
orcounty.sbn
、以及
orcounty.dbf
,并将所有五个文件都放在文件夹中:
c:/users/mark w miller/gis\in\u R/shapefile\u 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:
我可以通过以下方式阅读自然地球形状文件:

library(rgdal)

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

# read shapefile
wmap <- readOGR(dsn="ne_110m_physical", layer="ne_110m_land")
库(rgdal)
setwd(“c:/users/markw miller/gis\u in\u R/”)
#读取形状文件

wmap尝试从文件路径中删除最后一个“/”

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

我使用了ne_110m_land的文件

试试这个:

setwd('D:/JMSR/codes.R/mapas')
unzip("ne_110m_land.zip")
ogrInfo(".", "ne_110m_land")
wmap <- readOGR(".", "ne_110m_land")
setwd('D:/JMSR/codes.R/mapas')
解压(“ne_110m_land.zip”)
ogrInfo(“东北1.1亿土地”)

wmap对于任何在Linux机器上出现此错误的人,我发现问题在于使用了主路径快捷方式。i、 e

# Works
readOGR(dsn="/home/user/dir", layer="file")

# Doesn't work
readOGR(dsn="~/dir", layer="file")

我不知道为什么。

光栅::shapefile
环绕
readOGR
以处理路径和波浪线;只需传递完整的文件名

 library(raster)
 x <- shapefile("c:/users/orcounty.shp')
库(光栅)

我可以正常打开它。试试看
readOGR(dsn='c:/users/mark w miller/gis\u在/shapefile\u示例中,'layer='orcounty')
@PauloCardoso这很有效!我不敢相信解决办法如此简单。如果你想把它作为一个答案发布,我可以接受,或者我可以删除这个问题。波浪形表达式(
~
)通常由Unix shell扩展。如果您将它传递到R库调用中,它可能会被逐字读取。好的,谢谢。它通常在R中工作,用于读取文件、设置工作目录。在这种情况下,它没有。
# Works
readOGR(dsn="/home/user/dir", layer="file")

# Doesn't work
readOGR(dsn="~/dir", layer="file")
 library(raster)
 x <- shapefile("c:/users/orcounty.shp')
 y <- shapefile("~/users/orcounty.shp")