9

我有一些非常大的 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)
4

2 回答 2

8

Shapefile 是复合文件,它们将其属性数据存储在扩展名为*.dbf. (参考维基百科的 shapefile 文章。)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")
于 2012-11-14T17:59:28.923 回答
0
    FileInputStream fis = new FileInputStream( "/folder/file.dbf" ); 
DbaseFileReader dbfReader =  new DbaseFileReader(fis.getChannel(),false, Charset.forName("ISO-8859-1"));

        while ( dbfReader.hasNext() )   {
          final Object[] fields = dbfReader.readEntry();

          Long field1 = (Long) fields[0];
          Long field2 = (Long) fields[1];
          System.out.println("DBF field "+i+" value is: " + fields[0]);
          System.out.println("DBF field 2 value is: " + field2);
        }
 dbfReader.close();
 fis.close();
于 2013-02-06T06:41:21.367 回答