Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Having 10 raster files in one directory and another 10 rasters in another directory and both have the same dimensions.

directory 1:

    files1 <- list.files("C:\\2010", "*.envi", full.names = TRUE)
    s <- stack(files1)

directory 2:

 files2 <- list.files("C:\\2012", "*.envi", full.names = TRUE)
 s1 <- stack(files2)

I would like to filter s based on s1. I want to replace values in all layers in s by NA whenever corresponding layers in s1 have values greater than 0.6(corresponding pixels).

share|improve this question

1 Answer 1

Something like:

s1[s2 > 0.6] <- NA

This is the standard R way of doing things like this. You use s2 to make a subset in s1, and then you replace that subset by NA. You might need to do some looping if rasterstacks do not support this directly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.