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.
import arcpy import os from arcpy.sa import * from arcpy import env env.workspace=(r"C:\Users\cc\Desktop\tcamPractice") env.overwriteOutput = True outws=(r"C:\Users\cc\Desktop\tcamPractice\false") folders=arcpy.ListWorkspaces() for root, dirs, files in os.walk(r"C:\Users\cc\Desktop\tcamPractice"): for raster in files: rasterlist=arcpy.ListRasters("*", "TIF") outraster=outws+"comp.tif" if raster.find("Green")>0: band1=raster print band1 elif raster.find("Red")>0: band2=raster print band2 elif raster.find("Nir")>0: band3=raster print band3 #arcpy.CompositeBands_management([band3,band2,band1], outraster
Thanks Mr. Patterson.
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
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 .
Also, adding the tag "python" will also get more geonet users to see your posting.
...edit....oops, you beat me to it. Yea!