[R-sig-Geo] Changing values of raster pixels to NA
Zia Uddin Ahmed
zua3 at cornell.edu
Tue Aug 6 18:37:25 CEST 2013
You can try this:
files <- list.files(pattern='.tif$')
s <- stack(files)
names(s)
nl <- nlayers(s)
# Create Raster: values <1:
rc1<-function(x){
ifelse(x>1.000,0,
ifelse(x<=1.000,1,NA))}
r1.rc1<-calc(s,fun=rc1)
plot(r1.rc1)
r1<-r1.rc1*s
plot(r1)
# Create raster: values >=-1 and <=1
rc2<-function(x){
ifelse(x< -1.000,0,
ifelse(x>= -1.000,1,NA))}
r2.rc2<-calc(r1,fun=rc2)
r2<-r1*r2.rc2
plot(r2)
Zia
-----Original Message-----
From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Carlos Vázquez
Sent: Tuesday, August 06, 2013 4:54 AM
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] Changing values of raster pixels to NA
Hi to all,
I have a problem using raster stacks in R.
I have a set of raster layers with pixel reliability information for NDVI with pixel values of 0,1,2, and 3 Since i am not interested in values 2 and 3, I want to change all 2 and 3 values in the raster layers to NA's I am using the following formula:
NDVI[NDVI==3|NDVI==2]<-NA
It works fine for single rasters but when applying to a raster stack, it gives strange results, converting some 0 and 1 values to NA as well.
Any ideas of what might be wrong?
Any help will be appreciated.
Thanks in advance!
MSc. student
Carlos Vázquez
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list