Hi raster warriors!
I am having a headache with my results after months of manipulating my data set. I am new with R and spatial analysis but very happy in my learning process.
Here my issue: Once I apply the zonal function to a set of 5 raster objects (.tif), somehow I get duplicated values in zones where I suppose to get zero. Also, some values appear in other cells.
Here my code:
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)
here my results:
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
From 31 to 36 are the same as the ones from 1 to 6.
Here results of one of my colleagues – to whom I am comparing with
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
As you can see I get duplicated values.
Inputs can be found here ET, ED files
Any help is very much appreciated. Many thanks
Diego