Hello list, Im trying to calculate the porportion of overlap among two rasters. I think i got it done, but when I apply the script on identical rasters, the proportion obtained is not 1! Someone could please explain me what I could be missing here?
Here comes a reproducible example: library(raster) #generate 2 identical raster layers b and d that take values 0 and 1. wgs84 <- "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0" d <- raster() extent(d) <- extent(119.4993, 141.0993, -36.65831, -29.85831) res(d) <- c(0.08, 0.08) projection(d) <- CRS(wgs84) values(d) <- sample(c(0, 1), ncell(d), replace=TRUE) b=d # calculate each layers' area a=raster::area(d) s=cellStats(a, 'sum') #sum both layers, so as to have value 2 were both layers present value 1 soma=sum(b,d) overl=sum(values(area(soma))[which(values(soma)==2)])# sum cell sizes of cells with value 2 within soma overl/s# i think this should give 1 but it does not. # visualizing library(maps) map(regions = "australia") image(d, add = TRUE, col = "blue") image(soma, add = TRUE, col = "green") Thanks in advance! Agus -- Agustín Camacho Guerrero. Doutor em Zoologia. Laboratório de Herpetologia, Departamento de Zoologia, Instituto de Biociências, USP. Rua do Matão, trav. 14, nº 321, Cidade Universitária, São Paulo - SP, CEP: 05508-090, Brasil. [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo