为栅格堆栈提取面内的平均值

时间:2018-09-18 04:40:45

标签: r extract raster

我有一组栅格,我想对其进行迭代以提取每个栅格的面内平均值。但是,这是永远的。我可以从堆栈中创建光栅砖以帮助缩短处理时间吗?还有其他建议吗?我有69个栅格...但是如果确实需要,我可以将其减少到14个。

iterate_raster <- function(grids_location, shp_location, func){
        #list files (in this case raster TIFFs)
        grids <- list.files(grids_location, pattern = "*.tif$")
        #read-in the polygon shapefile
        shp <- readShapePoly(shp_location)
        #create a raster stack
        st <- paste0(grids_location, "/")
        s <- stack(paste0(st, grids))
        ex <- extract(s, shp, fun=func, na.rm=TRUE, df=TRUE, weights = TRUE)
        return(data.frame(ex))
}

df <- iterate_raster(dep, spsh, mean)

0 个答案:

没有答案