我使用两个栅格,每个栅格具有不同的分辨率。我想知道是否有一种更有效的方法将较粗的光栅分辨率与较精细的光栅分辨率相匹配。现在我正在使用蒙版功能来节省一些时间,剪辑到正确的范围并更改分辨率:
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
我也在尝试disaggregate
函数于raster
但我收到这个奇怪的错误!
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')