R:不同日期的栅格图层之间的插值 [英] R: Interpolation between raster layers of different dates

查看:242
本文介绍了R:不同日期的栅格图层之间的插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有4个栅格图层,并且具有相同的扩展范围,其中包含4个不同年份的数据:2006、2008、2010和2012:

Let's say I have 4 raster layers with the same extend with data of 4 different years: 2006,2008,2010 and 2012:

library(raster)

r2006<-raster(ncol=3, nrow=3)
values(r2006)<-1:9

r2008<-raster(ncol=3, nrow=3)
values(r2008)<-3:11

r2010<-raster(ncol=3, nrow=3)
values(r2010)<-5:13

r2012<-raster(ncol=3, nrow=3)
values(r2012)<-7:15

现在,我想通过对4个栅格图层的值进行内插/外推(线性方法应该是一个很好的开始)来为2006年至2013年之间(甚至更长)创建每年的栅格图层.结果应如下所示:

Now I want to create raster layers for every year between 2006 and 2013 (or even longer) by inter-/extrapolating (a linear method should be a good start) the values of the 4 raster layers. The result should look like this:

r2006<-raster(ncol=3, nrow=3)
values(r2006)<-1:9

r2007<-raster(ncol=3, nrow=3)
values(r2007)<-2:10

r2008<-raster(ncol=3, nrow=3)
values(r2008)<-3:11

r2009<-raster(ncol=3, nrow=3)
values(r2009)<-4:12

r2010<-raster(ncol=3, nrow=3)
values(r2010)<-5:13

r2011<-raster(ncol=3, nrow=3)
values(r2011)<-6:14

r2012<-raster(ncol=3, nrow=3)
values(r2012)<-7:15

r2013<-raster(ncol=3, nrow=3)
values(r2013)<-8:16

使用lm()approxExtrap似乎无济于事.

推荐答案

做到这一点的一种方法是将问题分成两部分:1.首先,对栅格值执行数字插值; 2.然后应用插值值适当的中间栅格图层.

One way to do this is to separate your problem into two parts: 1. First, perform the numerical interpolation on the raster values, 2. and apply the interpolated values to the appropriate intermediate raster layers.

想法:构建一个栅格图层的values()数据框架,对该数据框架进行时间索引,然后将线性插值应用于这些数字.对于线性插值,我使用simecol包中的approxTime.

Idea: Build a data frame of the values() of the raster layers, time index that data frame, and then apply Linear Interpolation to those numbers. For linear interpolation I use approxTime from the simecol package.

对于上面的示例,

library(raster)
library(simecol)    
df <- data.frame("2006" = 1:9, "2008" = 3:11, "2010" = 5:13, "2012"=7:15)

#transpose since we want time to be the first col, and the values to be columns
new <- data.frame(t(df))
times <- seq(2006, 2012, by=2)
new <- cbind(times, new)

# Now, apply Linear Interpolate for each layer of the raster
approxTime(new, 2006:2012, rule = 2)

这给出了:

#  times X1 X2 X3 X4 X5 X6 X7 X8 X9
#1  2006  1  2  3  4  5  6  7  8  9
#2  2007  2  3  4  5  6  7  8  9 10
#3  2008  3  4  5  6  7  8  9 10 11
#4  2009  4  5  6  7  8  9 10 11 12
#5  2010  5  6  7  8  9 10 11 12 13
#6  2011  6  7  8  9 10 11 12 13 14
#7  2012  7  8  9 10 11 12 13 14 15

然后您可以存储它,并取每一行并应用于该年的栅格对象的值.

You can then store this, and take each row and apply to the values of that year's raster object.

注意:roximateTime不做线性外推.它只是采用最接近的值,因此您需要考虑这一点.

Note: approxTime does not do linear extrapolation. It simply takes the closest value, so you need to account for that.

这篇关于R:不同日期的栅格图层之间的插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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