AnsweredAssumed Answered

Batch composite bands using arcpy

Question asked by BrunodeDeus on Dec 21, 2017
Latest reply on Dec 26, 2017 by xander_bakker
Branched from an earlier discussion

Branched from: Help: Batch - composite bands  Arc-python 

 

Hi,

I would like use this script, but it fails. Some hint?

 

import arcpy, os

arcpy.env.workspace = r'C:\Teste_Auto_CLEIA\Ima_compactadas'

# list all folders in a directory
folders = arcpy.ListWorkspaces("L8*", "Folder") # Inside main directory, already have other folders, but the bands are always inside folders that begin with "L8", e.g. "L8227069".

#The output files place
outws = r'C:\Teste_Auto_CLEIA\Imagem' # Line 9

for folder in folders:
    arcpy.env.workspace = folder
    rasters = arcpy.ListRasters("*.tif") # I already erased the bands which I won't use
    chk4 = ['band{0}.tif'.format(i) for i in range(0, 7)] # I changed the range
    rasters = [a for a in rasters if a[-9:] in chk4]
    name = os.path.join(outws, rasters[1].split("_")[0] + ".tif") # I wrote "outws"
    arcpy.CompositeBands_management(rasters, name) # I put it
    print(rasters)

 

 

I'm using ArcMap 10.1 and the bands names aren't the same, for instance, "LO82270682017183CUB00_B1", ... , "LO82270682017183CUB00_B7".

 

Thanks!

Outcomes