I want to create raster from 2 input rasters. how do I get pixel values that are the sum of the pixel values of the input rasters?
So i have classified rasters where non-water pixels are 0 and water pixels in one raster are 1 and in the other 2. So I want to get a new raster where 0 are the pixels where both rasters had non-water, 1 where only the first found water, 2 only the second and value 3 would mean that both rasters classified this pixel as water. Until now what i am doing is simply sum the raster.
library(raster)
reclass_df1 <- c(0, 2160, 1, 2160, Inf, 0)
reclass_df2 <- c(0, 2160, 2, 2160, Inf, 0)
reclass_msen1 <- matrix(reclass_df1, ncol = 3,byrow = TRUE)
reclass_msen2 <- matrix(reclass_df2, ncol = 3,byrow = TRUE)
ras2_1 <- reclassify(ras2[[1]],reclass_msen1)
ras2_1 <- reclassify(ras2[[2]],reclass_msen2)
ras2_combi <- ras2_1 + ras2_2
As output I expected to have values from 0 to 3. so that 0 would be where both rasters had non-water pixels, 1 when only the one raster, 2 the other and 3 when both rasters have water pixels. but i only get values 0,1 and 3 and i doubt that this can be correct.