質問: os.path.join(output, rasterlist[1].split("_")[0] + ".img") arcpy.CompositeBands_management(rasterlist, name) print(rasterlist) ``` I was trying these code but output is not created. It gave this error: ``` image:['T45QVD_20210104T044201_B02_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2', 'T44QRJ_20210102T045209_B03_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2', 'T44QRJ_20210102T045209_B03_10m.jp2', 'T44QRJ_20210102T045209_B04_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', n 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2', 'T44QRJ_20210102T045209_B03_10m.jp2', 'T44QRJ_20210102T045209_B04_10m.jp2', 'T44QRJ_20210102T045209_B08_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2', 'T44QRJ_20210102T045209_B03_10m.jp2', 'T44QRJ_20210102T045209_B04_10m.jp2', 'T44QRJ_20210102T045209_B08_10m.jp2', 'T44QRJ_20210102T045209_B11_20m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2', 'T44QRJ_20210102T045209_B03_10m.jp2', 'T44QRJ_20210102T045209_B04_10m.jp2', 'T44QRJ_20210102T045209_B08_10m.jp2', 'T44QRJ_20210102T045209_B11_20m.jp2', 'T44QRJ_20210102T045209_B12_20m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2', 'T44QRJ_20210102T045209_B03_10m.jp2', 'T44QRJ_20210102T045209_B04_10m.jp2', 'T44QRJ_20210102T045209_B08_10m.jp2', 'T44QRJ_20210102T045209_B11_20m.jp2', 'T44QRJ_20210102T045209_B12_20m.jp2', 'T45QUD_20210102T045209_B02_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2', 'T44QRJ_20210102T045209_B03_10m.jp2', 'T44QRJ_20210102T045209_B04_10m.jp2', 'T44QRJ_20210102T045209_B08_10m.jp2', 'T44QRJ_20210102T045209_B11_20m.jp2', 'T44QRJ_20210102T045209_B12_20m.jp2', 'T45QUD_20210102T045209_B02_10m.jp2', 'T45QUD_20210102T045209_B03_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2', 'T44QRJ_20210102T045209_B03_10m.jp2', 'T44QRJ_20210102T045209_B04_10m.jp2', 'T44QRJ_20210102T045209_B08_10m.jp2', 'T44QRJ_20210102T045209_B11_20m.jp2', 'T44QRJ_20210102T045209_B12_20m.jp2', 'T45QUD_20210102T045209_B02_10m.jp2', 'T45QUD_20210102T045209_B03_10m.jp2', 'T45QUD_20210102T045209_B04_10m.jp2'] image:['T45QVD_20210104T044201_B02_10m.jp2', 'T45QVD_20210104T044201_B03_10m.jp2', 'T45QVD_20210104T044201_B04_10m.jp2', 'T45QVD_20210104T044201_B08_10m.jp2', 'T45QVD_20210104T044201_B11_20m.jp2', 'T45QVD_20210104T044201_B12_20m.jp2', 'T44QRJ_20210102T045209_B02_10m.jp2', 'T44QRJ_20210102T045209_B03_10m.jp2', 'T44QRJ_20210102T045209_B04_10m.jp2', 'T44QRJ_20210102T045209_B08_10m.jp2', 'T44QRJ_20210102T045209_B11_20m.jp2', 'T44QRJ_20210102T045209_B12_20m.jp2', 'T45QUD_20210102T045209_B02_10m.jp2', 'T45QUD_20210102T045209_B03_10m.jp2', 'T45QUD_20210102T045209_B04_10m.jp2', 'T45QUD_20210102T045209_B08_10m.jp2'] Traceback (most recent call last): File "L:\Arcpy\Py_script\composite_band_script_1.py", line 35, in arcpy.CompositeBands_management(rasterlist, name) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 13647, in CompositeBands raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Rasters: ``` How can I solve that?
回答: A few lines of code you should take another look at: 1. Check the input parameters for file.endswith(). I suspect it expects a single string as input, rather than a tuple with many strings. 2. The first parameter of arcpy.CompositeBands_managment() expects all the rasters you are joining as a list, not one raster at a time. I would recommend at this point in the for loops you add the names to a list, and then after the for loops are finished run arcpy.CompositeBands_managment(input_list, newname). 3. Check if name = os.path.join() is outputting what you want it to. Specifically, whether file[1] gives you what you think it does.