匹配两个栅格的分辨率 [英] Matching the resolution of two rasters

查看:540
本文介绍了匹配两个栅格的分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理两个具有不同分辨率的栅格.我想知道是否有更有效的方法将较粗的光栅分辨率与较细的光栅分辨率匹配.现在,我正在使用遮罩功能节省一些时间,裁剪到正确的范围并更改分辨率:

Im working with two rasters each with a different resolution. Im wondering if there is a more efficient way of matching the coarser raster resolution to the finer raster resolution. Right now I am using the mask function to save some time, clip to the correct extent and change the resolution:

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函数,但出现了这个奇怪的错误!

Im also trying the disaggregate function in raster but I get this odd error!

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

这似乎暂时可行,但不确定其是否正确:

This seems to work for the time being but not sure if its correct:

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

推荐答案

为什么该Error: !is.null(fact) is not TRUE是奇数?如果查看?disaggregate,将看到没有参数nrows,但是有一个必需的参数fact,您没有提供.

Why would this Error: !is.null(fact) is not TRUE be odd? If you look at ?disaggregate you will see that there is no argument nrows, but there is a required argument fact, which you did not supply.

您可以

lc_r2a <- disaggregate (lc_r1, fact=12)

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

等效于

lc_r2c <- resample(lc_r1, r)

您为什么不确定这是正确的?

Why are you not sure that this is correct?

但是,考虑到您要遮罩lc_r1,逻辑方法是朝相反的方向更改遮罩的分辨率r

However, given that you want to mask lc_r1, the logical approach would be to go the opposite direction and change the resolution of your mask, r,

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

这篇关于匹配两个栅格的分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆