I have a list of multiband rasters, consisting of: Red=Band 1, NIR=Band 2, SWIR1=Band 3 and SWIR2= Band 4. What I want is to access only the red and NIR bands and save it to new file. Then, I'll be using them my Map Algebra calculations below.
(Note that accessing and saving the Red and NIR bands portion is still missing from my code)
import arcpy
from arcpy import env
from arcpy.sa import *
env.overwriteOutput = True
#Set the current workspace, assuming that all red and nir bands are already
#extracted and saved as individual bands
env.workspace = (r"C:\thesis\hansenwipfiles\first and last v1.0")
#Raster List (Assuming the rasters here are already single bands)
RedbandList = ["red20N_120E.tif", "red10N_120E.tif", "red20N_110E.tif",
"red10N_110E.tif"]
NIRbandList = ["NIR20N_120E.tif", "NIR10N_120E.tif", "NIR20N_110E.tif",
"NIR10N_110E.tif"]
for range in (0,4):
ndvi = Raster(NIRbandList[f])-Raster(RedbandList[f])/\
Raster(NIRbandList[f])+Raster(RedbandList[f])
ndviFloat = float(ndvi)
ouputName = ndviFloat
ndviFloat.save(ouputName)
print "Finish!"
I have not tested the code if it works, though no errors found after running the "Test Module".