Skip to content
Prev 171409 / 398503 Next

Extracting xy from raster based on raster value

Dear Kingsford
Thank you very much for your suggestion. It turns out I had downloaded an old version of raster. I also got a reply from the R-forge website with other suggestions.
In case anybody using the R-help list is?interested, here is the link:
http://r-forge.r-project.org/forum/message.php?msg_id=1269

Regards,
Michelle



----- Original Message ----
From: Kingsford Jones <kingsfordjones at gmail.com>
To: Michelle Greve <michelle_greve at yahoo.com>
Cc: R-help at r-project.org
Sent: Sunday, February 22, 2009 7:32:58 PM
Subject: Re: [R] 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: