Thanks Andrew, this works.  I appreciate it.

-brian



On Sat, Nov 23, 2013 at 10:27 AM, Andrew Vitale <vitale232@gmail.com> wrote:

>  Brian,
>
> This works, but it will use memory.  I guess it depends just how big that
> DEM is...
>
> -Andrew
>
>
> library(raster)
>
> ras <- raster(ncols=10,nrows=10)
> ras[] <- 1:100
>
> #now I want to get the cell numbers for cells > 50.  I don't see a good way
> #to do it.
>
> #An attempt with spatial points doesn't work:
>
> ras[ras<50] <- NA
> temp <- extract(ras, 1:ncell(ras), df = TRUE)
>
> cells <- temp$ID[which(!is.na(temp$layer))]
>
>
>  On 11/23/2013 10:48 AM, Brian Buma wrote:
>
> Thanks, but that does not do what I need.  As in my example, that just
> reclasses the raster, it doesn't return the cell numbers for the non-NA
> portions of the raster.  Calling SpatialPoints on the raster with NA
> likewise does not return the non-NA cells only.
>
>
>
>
> On Fri, Nov 22, 2013 at 11:51 PM, Roman Luštrik <roman.lustrik@gmail.com> <roman.lustrik@gmail.com>wrote:
>
>
>  Try this.
>
> library(raster)
> ras <- raster(ncols=10,nrows=10)
> ras[] <- 1:100
>
> par(mfrow = c(1, 2))
> plot(ras)
> ras[ras[] > 50] <- NA
> plot(ras)
>
>
> Cheers,
> Roman
>
>
>
>
> On Sat, Nov 23, 2013 at 7:58 AM, Brian Buma <brian.buma@uas.alaska.edu> <brian.buma@uas.alaska.edu>wrote:
>
>
>  Hello all,
>
> I'm trying to extract the cell numbers from a raster in R based on a
> logical.  For example:
>
>
> ras <- raster(ncols=10,nrows=10)
> ras[] <- 1:100
>
> #now I want to get the cell numbers for cells > 50.  I don't see a good
> way
> to do it.
> #An attempt with spatial points doesn't work:
>
> temp <- SpatialPoints(ras>50)
> out <- cellFromXY(ras,temp)
>
> #nor does reclassing the raster
> ras[ras<50] <- NA
>
>
> I hope this isn't an obvious question, but I'm just not seeing it.  For
> what it's worth, I'm analyzing a large DEM and want to skip elevations
> that
> equal zero, rather than process those as well as the rest.  The current
> code is quite efficient (no for loops, vectorized) but the dataset is so
> large it takes a while.  The process runs off of cell numbers (currently
> running all the cells), so if I could not analyze those cell numbers at
> all, so much the better.
>
> Thanks.  I imagine there's a simple, elegant solution I'm just not seeing
> for some reason.
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing listR-sig-Geo@r-project.orghttps://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>  --
> In God we trust, all others bring data.
>
>
>  	[[alternative HTML version deleted]]
>
>
>
>
> _______________________________________________
> R-sig-Geo mailing listR-sig-Geo@r-project.orghttps://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> --
> Andrew Vitale
> Master's Student
> Department of Geography
> University of Nevada, Renovitale232@gmail.com
>
>

	[[alternative HTML version deleted]]

