我正在尝试将高分辨率(25米)和分类数据(1至13)的森林覆盖栅格重新采样为具有较低分辨率(约1公里)的新RasterLayer
。我的想法是将森林覆盖数据与其他低分辨率的栅格数据结合起来:
I tried
raster::resample()
, but since the data is categorical I lost a lot of information:summary(as.factor(df$loss_year_mosaic_30m)) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 3777691 65 101 50 151 145 159 295 291 134 102 126 104 91
As you can see, the new raster has the desired resolution but have lots of zeros as well. I suppose that is normal since I used the ´ngb´ option in
resample
.The second strategy was using
raster::aggregate()
but I find difficult to define a factor integer since the change of resolution is not straightforward (like the double of the resolution or alike).My high-resolution raster has the following resolution, and I want it to aggregate it to a
0.008333333, 0.008333333 (x, y)
resolution to the same extent.loss_year class : RasterLayer dimensions : 70503, 59566, 4199581698 (nrow, ncol, ncell) resolution : 0.00025, 0.00025 (x, y) extent : -81.73875, -66.84725, -4.2285, 13.39725 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 data source : /Volumes/LaCie/Deforestacion/Hansen/loss_year_mosaic_30m.tif names : loss_year_mosaic_30m values : 0, 13 (min, max)
I have tried a factor of ~33.33 following the description of the
aggregate
help: "The number of cells is the number of cells of x divided byfact*fact
(when fact is a single number)." Nonetheless, the resulting raster data do not seem to have the same number of rows and columns as my other low-resolution rasters.
我从未使用过这些高分辨率数据,而且我的计算能力也有限(可以使用clusterR
并行化一些命令,但有时它们需要的时间与非并行化的命令相同,特别是对于最近邻计算不起作用的情况)。
我缺乏想法;也许我可以尝试layerize
来获得计数栅格,但我必须进行“聚合”,然后出现了factor
问题。由于这些过程需要花费我几天的时间,因此我想知道创建低分辨率栅格的最有效方法,同时又不会失去太多信息。
以下是一个可重复的示例:
r_hr <- raster(nrow=70, ncol=70) #High resolution raster with categorical data
set.seed(0)
r_hr[] <- round(runif(1:ncell(r_hr), 1, 5))
r_lr <- raster(nrow=6, ncol=6) #Low resolution raster
第一策略:信息丢失
r <- resample(r_hr, r_lr, method = "ngb") #The raster data is categorical
第二种策略:难以定义聚合因素。
r <- aggregate(r_hr, factor) #How to define a factor to get exactly the same number of cells of h_lr?
另一个选择:layerize
r_brick <- layerize(r_hr)
aggregate(r_brick, factor) #How to define factor to coincide with the r_lr dimensions?
感谢您的帮助!