从shapefile(R)只读数据槽?

att*_*ool 7 r geospatial shapefile rgdal

我有一些非常大的shapefile.我可以SpatialPolygonsDataFrame使用该rgdal函数将它们读入readOGR,但每个文件需要很长时间.我实际上只对插槽data.frame中显示的内容感兴趣@data.有没有办法只读取数据,跳过资源密集型多边形?

示例代码:

## State of Alabama census blocks (152 MB compressed, 266 MB uncompressed)
shpurl <- "http://www2.census.gov/geo/tiger/TIGER2011/TABBLOCK/tl_2011_01_tabblock.zip"
tmp    <- tempfile(fileext=".zip")
download.file(shpurl, destfile=tmp)
unzip(tmp, exdir=getwd())

## Read shapefile
nm  <- strsplit(basename(shpurl), "\\.")[[1]][1]
lyr <- readOGR(dsn=getwd(), layer=nm)

## Data I want
head(lyr@data)
Run Code Online (Sandbox Code Playgroud)

Jos*_*ien 7

Shapefile是复合文件,它们将属性数据存储在带扩展名的文件中*.dbf.(请参阅维基百科文章shape文件用于参考.)的dbf后缀是指dBASE文件格式,其可以由函数读取read.dbf()foreign包.

所以,试试这个:

library(foreign)
df <- read.dbf("tl_2011_01_tabblock.dbf")
## And, more generally, read.dbf("path/to/shapefile/shapefile-name.dbf")
Run Code Online (Sandbox Code Playgroud)