本文介绍了rgdal/readOGR-无法从.zip读取shapefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载zip级别的shapefile,以进行以下绘制: https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles http://www.nceas.ucsb.edu/scicomp/usecases/ReadWriteESRIShapeFiles等等

I'm trying to load a zip level shapefile to do some plotting, per:https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefileshttp://www.nceas.ucsb.edu/scicomp/usecases/ReadWriteESRIShapeFilesetc

我的代码:

library(rgdal)
library(RColorBrewer)
library(ggplot2)
zipmap = readOGR(dsn="file.zip/", layer="myZIPmap")

我收到此错误:

Error in ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding = input_field_name_encoding) :
  Cannot open file

我检查了驱动程序,但老实说我无法解释输出:

I checked the drivers but to be honest am not able to interpret the output:

ogrDrivers()
             name write
1      AeronavFAA FALSE
2          ARCGEN FALSE
3          AVCBin FALSE
4          AVCE00 FALSE
5             BNA  TRUE
6             CSV  TRUE
7             DGN  TRUE
8             DXF  TRUE
9          EDIGEO FALSE
10 ESRI Shapefile  TRUE
11     Geoconcept  TRUE
12        GeoJSON  TRUE
13       Geomedia FALSE
14         GeoRSS  TRUE
15            GML  TRUE
16            GMT  TRUE
17       GPSBabel  TRUE
18  GPSTrackMaker  TRUE
19            GPX  TRUE
20            HTF FALSE
21         Idrisi FALSE
22            KML  TRUE
23   MapInfo File  TRUE
24         Memory  TRUE
25   MSSQLSpatial  TRUE
26           ODBC  TRUE
27        OpenAir FALSE
28         PCIDSK  TRUE
29            PDS FALSE
30         PGDump  TRUE
31           PGeo FALSE
32            REC FALSE
33            S57  TRUE
34           SDTS FALSE
35       SEGUKOOA FALSE
36           SEGY FALSE
37            SUA FALSE
38            SVG FALSE
39          TIGER  TRUE
40        UK .NTF FALSE
41            VFK FALSE
42            VRT FALSE
43         XPlane FALSE

file.info给出:

file.info gives:

 file.info(path="K:/2012 - IPD - Policy Maps/fe_2007_us_zcta500.zip/")
                                                             size isdir mode               mtime               ctime
    K:/2012 - IPD - Policy Maps/fe_2007_us_zcta500.zip/ 661131516 FALSE  666 2012-08-22 14:54:53 2012-08-22 14:50:43
                                                                      atime exe
    K:/2012 - IPD - Policy Maps/fe_2007_us_zcta500.zip/ 2012-08-22 14:58:38  no

鉴于我尝试过的互联网搜索,看来我不是唯一遇到此问题的人,但我一直找不到答案.我不确定问题是否与shapefile位于.zip文件夹内有关.由于它是一台工作计算机,因此我必须等待IT人员安装WinZip,以便我可以提取shapefile并在.zip文件夹之外尝试.希望那将是明天.

Given the internet searches I've tried, it looks like I'm not the only one having this issue but I've been unable to find an answer. I'm not sure if the problem is related to the shapefile being inside a .zip folder or not. As it's a work computer, I have to wait for IT to install WinZip so that I can extract the shapefile and try outside a .zip folder. Hopefully that will be tomorrow.

此外,程序包帮助还指出请注意,数据源目录(例如* .dbf)中的杂散文件可能会导致伴随* .shp丢失的严重错误." .zip文件夹具有以下内容:a.dbf,b.prj,c.shp,d.shp.xml,e.shx.

Also, the package help states "Note that stray files in data source directories (such as *.dbf) may lead to suprious errors that accompanying *.shp are missing." The .zip folder has the following: a.dbf, b.prj, c.shp, d.shp.xml, e.shx.

您能提供的任何帮助都会很棒!-亚历克斯

Any help you can provide would be wonderful!-Alex

推荐答案

您应该能够解压缩文件,而无需使用unzip的外部程序.要读取带有readOGR的shapefile,dsn是您的解压缩"文件所在的目录名称,而layer是您的形状文件的名称,不带扩展名.在下面的示例中,将myZIPmap替换为适当的shapefile名称.

You should be able to unzip the files without the need of an external program with unzip. To read a shapefile with readOGR, the dsn is the directory name of where your 'unzipped' files are located, and layer is the name of your shape file without the extension. In the example below, replace myZIPmap with the appropriate shapefile name.

library(utils)
library(rgdal)

unzip("K:/2012 - IPD - Policy Maps/fe_2007_us_zcta500.zip")
zipmap <- readOGR(dsn = "K:/2012 - IPD - Policy Maps/fe_2007_us_zcta500", layer = "myZIPmap" )

这篇关于rgdal/readOGR-无法从.zip读取shapefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 08:30