Skip to content
Prev 15336 / 29559 Next

continuous raster to binary

What a fabulous collection of answers!  
 
For my bigger grids that can't reside in memory, I think I need to use calc in regards to Thierry's and Matt's approach, like this:
 
func <- function(x){x > 3.5}  #still need to add "as
r <- calc(r, fun=func, filename = ...)
 
So, following Rafael's note that reclass was faster than subs alone, here are timings on real data comparing reclass to calc.
user  system elapsed 
 119.16   28.00  147.37
user  system elapsed 
 119.85   28.38  148.44 
They are very close, and perhaps not even significantly different, but calc may be edging out reclass by a small amount.  Brilliant!
 
Thanks everyone, for the help. 
Best,
Tim
In terms of Tim's example:

plot(r)
r[] <- as.numeric(r[] > 3.5)
plot(r)

works for me.  Made only a small change from Thierry's elegant example 
to return numeric instead of boolean.

M
On 6/14/2012 9:56 AM, ONKELINX, Thierry wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120614/6c2413e5/attachment.html>