[R-sig-Geo] Extract cell numbers from raster based on condition

Robert J. Hijmans r.hijmans at gmail.com
Sun Nov 24 04:22:11 CET 2013


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:
> Hi Brian,
>
> To get cell numbers of raster NA values, use this:
>
> cellnb.na <- Which(is.na(ras), cells = TRUE)
>
> Guillaume
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Extract-cell-numbers-from-raster-based-on-condition-tp7585169p7585174.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list