Select to view content in your preferred language

Python Script to iterate numerous, single-band rasters for arcpy.CompositeBands

04-14-2015 09:54 AM
New Contributor

I have a large collection of single-band geotiffs (NIR, Green, and Red) that I would like to composite using a Python script. The goal is to iterate through multiple folders in a main directory, identify each tiff as band1, band2, band3 to input into CompositeBands_management, and do this for every raster scene. To clarify, each image number, i.e. scene, has three single-band tiffs associated. For example, the naming convention is: TTC2500_Green_Channel_8.TIF where TTC2500 is the image number.

So far, my script can go through each folder and identify the specific bands based on the filename b...

import arcpy
import os
from import *
from arcpy import env

env.overwriteOutput = True


for root, dirs, files in os.walk(r"C:\Users\cc\Desktop\tcamPractice"):

    for raster in files:
        rasterlist=arcpy.ListRasters("*", "TIF")
        if raster.find("Green")>0:
            print band1
        elif raster.find("Red")>0:
            print band2
        elif raster.find("Nir")>0:
            print band3
        #arcpy.CompositeBands_management([band3,band2,band1], outraster

Thanks Mr. Patterson.

0 Kudos
2 Replies
MVP Emeritus

could you edit your post and use the Use Advanced Editor option and format your code using Python syntax.  Use Advanced Editor will be available when you access this thread directly and not through the mail notification

MVP Emeritus

The reason Dan is requesting that is spacing is very important in Python.  A cut-n-paste to GeoNet, without it the spacing correct makes it hard for others to debug since the first response will be your indentation being off. This link might help you modify you post .

Posting Code blocks in the new GeoNet

Also, adding the tag "python" will also get more geonet users to see your posting.

...edit....oops, you beat me to it.  Yea!