Skip to content
Prev 19843 / 29559 Next

Extract cell numbers from raster based on condition

Brian,

Andrew's approach works, but you really should not do it that way. It
is inefficient due to the use of extract. Rather than extract(x,
1:ncell(x) you could do the much more direct values(x). The code could
also lead to an error due to memory limitations whereas the other two
approaches (Which or rasterToPoints) might work for the same data (if
there are relatively many NA values).

Andrew improved the original   ras[ras[] > 50] <- NA  to the much
better  ras[ras > 50] <- NA ; again because that will work with large
files, but reclassify(ras,  cbind(50, Inf, NA)) would be my
preference. I understand that you may only use relatively small files,
but as the archives of this mailing list are a resource for many, I am
compelled to explain this such that others won't get into trouble.

(The next questions is whether you actually need to extract cell
numbers for what you want to accomplish (this is often done but rarely
needed) ---- but that is not the topic of your post)

Robert
On Mon, Nov 25, 2013 at 7:49 AM, Brian Buma <brian.buma at uas.alaska.edu> wrote: