我一直在使用raster
软件包中的extract
函数,使用由shapefile定义的区域从栅格文件中提取数据。但是,我现在遇到了这个过程所需的内存量问题。我有很多shapefile文件(~1000),而栅格文件很大(~1.6gb)。
我的处理方式是:
shp <- mclapply(list.files(pattern="*.shp",full.names=TRUE), readShapePoly,mc.cores=6)
ndvi <- raster("NDVI.dat")
mc<- function(y) {
temp <- gUnionCascaded(y)
extract <- extract(ndvi,temp)
mean <- range(extract, na.rm=T )[1:2]
leng <- length(output)
}
output <- lapply(shp, mc)
我能采取哪些措施来减少内存负载?我尝试加载更少的shapefile,在大约5分钟后它起了作用,但内存再次飙升了。我的电脑是四核2.4GHz,带8GB内存。