I am trying to stack bands 3 and 4 together for numerous landsat scenes, and I am trying to do it using a loop and arcpy.CompositeBands_management
. The code I am using is:
import arcpy
#set environment
arcpy.env.workspace=r'F:\Sheyenne\Atmospherically Corrected Landsat\hank_masked\NDVI'
#path to band 3
band3 = arcpy.ListRasters("*band3*")
#path to band 4
band4 = arcpy.ListRasters("*band4*")
#loop that matches raster names and only executes process for those that match
for raster in band3:
rasterName = raster
stack = "" #initialize your variable to be populated in the inner loop
for band in band4:
if band.startswith(rasterName.split("_")[0]):
stack = band
break #break out of the inner loop - we have a match
if stack != "": #just to make sure we have something
#generic naming
outraster = rasterName.replace(".tif", "_stacked.tif")
arcpy.CompositeBands_management('rasterName;stack',outraster)
print('Done Processing')
but this returns the error:
ExecuteError: ERROR 000271: Cannot open the input datasets
Failed to execute (CompositeBands).
I am thinking it has something to do with this line:
arcpy.CompositeBands_management('rasterName;stack',outraster)
If i take the '
out of this line it still won't work though
Edit:
If it helps at all, when I print out the variables rasterName
, stack
and outraster
they are populated as I would expect
stack
. I use this code for other processes as well and change the variable names