I have different bands separated in different file directory.
I used Raster Calculator to calculate NDVI using "NIR1.tif"-"RED1.tif"/"NIR1.tif"+"RED1.tif" as formula.
The link below describes a loop for StackBand which I supposed is a file containing different bands. In my case, I have separate file path for NIR and RED.
Data is named NIR1...NIR2000.tif and RED1...RED2000.tif.
I prefer using R but I am having difficulties in calling NIR and RED and putting them in a loop to calculate NDVI.
Below is my code:
library(raster) library(rgdal) NDVI< list.files("C:\\Users\\path\\Desktop\\PET\\sample\\", pattern="*.tif", all.files=F, full.names = FALSE, recursive = TRUE, ignore.case = FALSE) for (i in 1:length(NDVI)) NDVI <- raster(function(x,y) (x="NIR"+str(i)+".tif"), (y="red"+str(i)+".tif"), (x-y/x+y) writeRaster(NDVI,"NDVI", format="GTiff")
I tried to make some revisions in the code.