No problem I was on my phone so I couldnt test it to see how fast the
various methods were.
I really like Roberts approach because of the elegance and safe memory
approach. There is nothing
more fustrating that doing a 'raster' operation and getting back out of
memory error.
On Thu, Oct 18, 2012 a
Ani,
Here are some alternatives approaches.
# your data
m1<-matrix(c(1,1,1,2,2,2,3,3,3),ncol=3,byrow=TRUE)
m2<-matrix(c(1,2,1,1,2,3,2,3,3),ncol=3,byrow=TRUE)
r1<-raster(m1)
r2<-raster(m2)
# I think this is the most elegant approach for mutli-layer
reclassification problem.
# caveat: it may be sl
Thank you Etienne and Steven for your suggestions.
I tried the ordinary matrix method as suggested by Etienne. It works
fine. It was fast and produced excellent results for my original
raster files with 10 values.
Steven, when I try to incorporate more number of cell values, the
procedure is gett
reclassify r1 to 1 and 0. reclassify r2 to 0 1 and 2.
then multiply the rasters.
so r1 becomes 0 for all values ecept 1. r2 is 1 or 2 or 0. and the product
r3 will be 1 or 2 or 0
On Oct 17, 2012 11:55 AM, "aniruddha ghosh" wrote:
> Dear List,
> I have two raster layers (r1 and r2) and the cells h
Aniruddha,
One way is to treat it as an ordinary matrix...
r3 <- raster(matrix(0, ncol = 3, nrow = 3))
r3[r1[] == 1 & r2[] == 1] <- 1
r3[r1[] == 1 & r2[] == 2] <- 2
r3[1,1]; r3[1,2]
Etienne
2012/10/17 aniruddha ghosh
> Dear List,
> I have two raster layers (r1 and r2) and the cells have valu
Dear List,
I have two raster layers (r1 and r2) and the cells have values ranging 1 to
10. I want to create a new raster layer from these two with different
conditions like:
1) if r1==1 and r2==1, then r3 should be 1
2) if r1==1 and r2==2, then r3 should be 2
else 0 etc
With the following example: