Arcpy create composite images from several single band tifs

3622
11
02-05-2014 11:56 PM
JoshuaAhmed
Deactivated User
Hi,

I have a folder containing 7 tif rasters that I would like to combine into one composite tif. I have to do this for many images so I have written a python script to speed up to process. However, I'm having some trouble collecting all of the bands from the folder and creating a composite. Any help would be much appreciated.

import arcpy, sys, os
from arcpy import env
from arcpy.sa import *
arcpy.env.overwriteOutput = True #set the script to overwrite files
#the path to where the images are stored - will need to change for each set of images as the end folders are different
path_images = "J:/Proj/Annual_time_series/Landsat Images/1987/1_001_070/"
for root, dirs, files in os.walk(path_images):
    for name in files:
        beni87 = os.path.join(root,name)
        if beni87.endswith[('B10.TIF', 'B20.TIF', 'B30.TIF', 'B40.TIF', 'B50.TIF', 'B60.TIF', 'B70.TIF')] == True: #collect band 1,2 and 3 image
            tilename = name[0:-7] #remove the band number and .tif from the end of each image to be renamed
            print tilename + "being processed."
            #the list of banded images need to be put here, or the file containing the list needs to be put here
            in_rasters = path_images + name #input the bands from the file
            out_raster = path_images + tilename + "composite.tif" #insert the name of the image between the quotation marks
            #start composite bands processing
            arcpy.CompositeBands_management(in_rasters, out_raster)
11 Replies
SteveLynch
Esri Regular Contributor
The Walk function was made available at ArcGIS 10.1 Service Pack 1.

http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000023000000
0 Kudos
AshleyNewby
Deactivated User
That worked!! All 7 layers of the .img show in ERDAS now 🙂 Thanks so much!
0 Kudos