Skip to content

Extract cell numbers from raster based on condition

5 messages · Roman Luštrik, Brian Buma, Guillaume Drolet +1 more

#
And to get the cell numbers of cells with a value > 50 you can do

library(raster)
ras <- raster(ncols=10,nrows=10)
ras[] <- 1:100

# following Guillaume
Which(ras > 50, cells = TRUE)

# or like this (and this also returns the cell values ( p[, 3] ):
p <- rasterToPoints(ras, fun=function(x){x>50})
cellFromXY(ras, p[,1:2])

Robert

On Sat, Nov 23, 2013 at 4:01 PM, Guillaume Drolet
<droletguillaume at gmail.com> wrote: