[R-sig-Geo] How to sum area of adjacent patches?

Hugo Costa hugo@gco@t@ @ending from gm@il@com
Fri Nov 23 23:13:20 CET 2018


Deal all,

I'm merging several rasters representing patches of forest, and the pixel
values represent the area of the patches. The patches' area should be
summed along the edges of the merged rasters. I provide a reproducible
example. Any help is welcome.
Hugo

library(raster)
r1<-raster(nrows=10, ncols=10, xmn=0, xmx=1, ymn=0, ymx=1)
r2<-raster(nrows=10, ncols=10, xmn=0, xmx=1, ymn=1, ymx=2)
r1[]<-c(rep(24,24), rep(0,76))
r2[]<-c(rep(0,86), rep(14,14))
par(mfrow=c(2,2)); plot(r1,main="r1"); plot(r2,main="r2")


r3<-merge(r1,r2) ; plot(r3, main="merged rasters")

# do something

r3[r3>0]<-38     ; plot(r3, main="desired result")

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list