This one!
import arcpy, sys, os from arcpy import env arcpy.env.overwriteOutput = True path_images = "C:/temp/python/raster" rasterList = [] x = 1 for root, dirs, files in os.walk(path_images): for name in files: bands = os.path.join(root,name) if bands.endswith(".TIF") or bands.endswith(".tif"): rasterList.append(bands) if len(rasterList) > 0: out_raster = path_images + "/" + 'raster' + str(x) + ".img" arcpy.CompositeBands_management(rasterList, out_raster) rasterList = [] x += 1
if f.endswith(".TIF"):
if f.endswith(".TIF") or f.endswith(".tif"):
Traceback (most recent call last): File "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript debugger.run(codeObject, __main__.__dict__, start_stepping=0) File "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 655, in run exec cmd in globals, locals File "C:\Temp\landsatLayerStk.py", line 4, in <module> import arcpy, sys, os File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 12073, in CompositeBands raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000735: Input Rasters: Value is required Failed to execute (CompositeBands).
import arcpy, os #arcpy.env.workspace = "C:/Test" arcpy.env.overwriteOutput = True myDir = arcpy.GetParameterAsText(0) bands = [] #?myDownloads = os.listdir(myDir) try: #Walk through directories for root, dirs, files in os.walk(myDir): arcpy.env.workspace = root for f in files: if f.endswith(".TIF"): bands.append(f) #print bands a = ','.join(bands) b = a.replace(",",";") #[f.replace(",", ";") for f in bands] arcpy.CompositeBands_management(b, f[:-7] + ".img") print bands bands=[] print b except: print "Tool did not run" print arcpy.GetMessages()
import arcpy, sys, os from arcpy import env from arcpy.sa import * arcpy.env.overwriteOutput = True path_images = "C:/test" #arcpy.GetParameterAsText(0) rasterList = [] for root, dirs, files in os.walk(path_images): for name in files: bands = os.path.join(root,name) #print bands if bands.endswith(".TIF"): rasterList.append(bands) tilename = name[0:-7] #print tilename + " is being processed." print rasterList out_raster = path_images + "\\" + tilename + ".img" print out_raster #arcpy.CompositeBands_management(rasterList, out_raster) rasterList = [] print rasterList
Hi Josh,Try passing a list of the rasters to the Composite Bands tool. Try the following:import arcpy, sys, os from arcpy import env from arcpy.sa import * arcpy.env.overwriteOutput = True path_images = "J:/Proj/Annual_time_series/Landsat Images/1987/1_001_070/" rasterList = [] 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')): rasterList.append(beni87) tilename = name[0:-7] print tilename + "being processed." out_raster = path_images + "\\" + "composite.tif" arcpy.CompositeBands_management(rasterList, out_raster)Also, when posting code, be sure to enclose it with CODE tags using the # symbol above.
import arcpy, sys, os from arcpy import env from arcpy.sa import * arcpy.env.overwriteOutput = True path_images = "J:/Proj/Annual_time_series/Landsat Images/1987/1_001_070/" rasterList = [] 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')): rasterList.append(beni87) tilename = name[0:-7] print tilename + "being processed." out_raster = path_images + "\\" + "composite.tif" arcpy.CompositeBands_management(rasterList, out_raster)
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.