匹配两个栅格的分辨率

3

我正在处理两个分辨率不同的栅格数据。我想知道是否有更高效的方法将较粗的栅格数据匹配到较细的栅格数据上。目前,我正在使用掩膜函数来节省时间,对其进行截取并更改分辨率:

library(raster)
#the raster template with the desired resolution        
r <- raster(extent(-180, 180, -64, 84), res=0.04166667) 
# set some pixels to values, others to NA
r <- setValues(r, sample(c(1:3, NA), ncell(r), replace=TRUE))

#load the raster 
lc_r1 <- raster(r)
res(lc_r1) <- 0.5
values(lc_r1) <- 1:ncell(lc_r1)
lc_r1
##class       : RasterLayer 
##dimensions  : 296, 720, 213120  (nrow, ncol, ncell)
##resolution  : 0.5, 0.5  (x, y)
##extent      : -180, 180, -64, 84  (xmin, xmax, ymin, ymax)
##coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
##data source : in memory
##names       : layer 
##values      : 1, 213120  (min, max)

#create the new finer resolution raster.
lc_r2 <- mask (lc_r1, r2)
Error in compareRaster(x, mask) : different number or columns

我也在尝试使用raster中的disaggregate函数,但是我收到了一个奇怪的错误!

lc_r2 <- disaggregate (lc_r1, nrows=3600 )
Error: !is.null(fact) is not TRUE

这似乎暂时可以工作,但不确定是否正确:
lc_r2 <- disaggregate (lc_r1, fact=c(12,12 ), method='bilinear')
1个回答

3
为什么会出现这个错误:Error: !is.null(fact) is not TRUE?如果您查看?disaggregate,您会发现没有nrows参数,但是有一个必须的参数fact,而您没有提供它。
您可以执行以下操作:
lc_r2a <- disaggregate (lc_r1, fact=12)

或者

lc_r2b <- disaggregate(lc_r1, fact=12, method='bilinear')

这相当于

lc_r2c <- resample(lc_r1, r)

为什么你不确定这个是正确的?

然而,考虑到您想要掩盖lc_r1,逻辑上的方法是朝相反方向去,改变掩膜r的分辨率。

ra <- aggregate(r, fact=12, na.rm=TRUE) 
lcm <- mask(lc_r1, ra)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接