1

I have more than 2000 TIFF files of an NDVI index. I would like to check if I made it properly and if all of values are between -1 and 1.

How can I save everything to a text file to check max and min values as a summary of all files to not do it one by one?

I was trying to use RasterStack to combine all files in one, but it does not work...

Any other ideas?

  • Welcome to SO! Reference image files and a code sample with desired output (a.k.a. a minimum reproducible example) wld help folks help you. – hrbrmstr Oct 28 '17 at 13:38
  • you may do that right in R directly – Elio Diaz Oct 28 '17 at 14:42
  • Can you write a "for" loop over the raster file names? Do you know how to get a vector of all files from a folder? Then loop over those? – Spacedman Oct 28 '17 at 17:27
1

you may run a for loop, here the code takes two single rasters (out of rasterstacks) and puts their range in a data.frame

 a <- getData('worldclim', var='tmin', res=10)
    b <- getData('worldclim', var='tmax', res=10)
    a1 <- a$tmin1
    b1 <- b$tmax1
    ab <- list(a1,b1)
    cellStats(b1,"range")
    df <- data.frame()
    for(i in ab){
      df <- rbind(df, cellStats(i,"range"))
    }
df
1

Outline solution:

rasters = list.files(pattern = "*.tif$")
ranges = do.call(
           rbind,
          lapply(
            rasters, 
            function(rname){r = raster(rname); range(r[])})
          )

For a working directory where I have two tif files, I get:

> ranges
          [,1]     [,2]
[1,]  47.14706 2109.250
[2,] 283.35699 2848.571

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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