Skip to content
Prev 171326 / 398503 Next

Extracting xy from raster based on raster value

Hi Michelle,

The r-sig-geo list would be the ideal place for this question since
the authors of 'raster' would be likely to see it.

I haven't used the raster package before, but this seems to work:


#install.packages("raster", repos="http://R-Forge.R-project.org")
r <- raster()
r <- setValues(r, sample(1:27, ncell(r), replace=1))
plot(r)
r[] <- r[]==1
plot(r)

If you'd rather have the non-1 cells be NA, just replace 'r[]==1' with
'ifelse(r[]==1, 1, NA)'

hth,

Kingsford Jones


On Sat, Feb 21, 2009 at 8:46 AM, Michelle Greve
<michelle_greve at yahoo.com> wrote: