嗨光栅战士!
经过数月的数据处理后,我对自己的结果感到头疼。我是 R 和空间分析的新手,但对我的学习过程非常满意。
这是我的问题:一旦我将 zonal 函数应用于一组 5 个栅格对象 (.tif),我会以某种方式在我认为为零的区域中获得重复值。此外,一些值出现在其他单元格中。
这是我的代码:
folder <- "my_directory"
#for one country
ET<-raster("my_directory/file_ET.tif")
ED<-raster("my_directory/file_ED.tif")
SH<-raster("my_directory/file_SH.tif")
SC<-raster("my_directory/file_SC.tif")
WH<-raster("my_directory/file_WH.tif")
#zones
lowbound<- seq(0,cellStats(ED,"max", na.rm=TRUE),1000)
upbound<-lowbound+1000
band<-upbound/1000
rclmat <- as.matrix(cbind(lowbound,upbound,band)) #to be used on reclassify
rclmat<-rclmat[1:length(rclmat[,1])-1,]
edb<- reclassify(ED, rclmat)
# zonal statistics # I already tried this: na.rm=FALSE, !anyDuplicated(sum_ET)) to avoid duplication – did not work
sum_ET<-zonal(ET,edb,"sum") #, na.rm=FALSE, !anyDuplicated(sum_ET))
stats<-cbind(band,upbound,sum_ET[,2], sum_SH[,2], sum_SC[,2], sum_WH[,2],perc_SH,perc_SC,perc_WH,perc_Tot)
这是我的结果:
upbound ET
1 1000 10523272.53
2 2000 5156046.27
3 3000 5053895.54
4 4000 4796505.3
5 5000 4392162.97
6 6000 4156065.87
31 31000 10523272.53
32 32000 5156046.27
33 33000 5053895.54
34 34000 4796505.3
35 35000 4392162.97
36 36000 4156065.87
从 31 到 36 与从 1 到 6 相同。
这是我的一位同事的结果——我正在与之比较
upbound ET
1 1000 10523272.53
2 2000 5156046.27
3 3000 5053895.54
4 4000 4796505.3
5 5000 4392162.97
6 6000 4156065.87
31 31000 0
32 32000 21247.26
33 33000 0
34 34000 0
35 35000 0
36 36000 23877.74
如您所见,我得到了重复的值。
输入可在此处找到ET、ED 文件
很感谢任何形式的帮助。非常感谢
迭戈