python - Batch processing raster images with Arcpy -
i'm attempting write code in python stack 5 band raster images listed sequentially in folder , output stacked images new folder. first instinct automate sort of loop structure in arcpy composite band tool.
i'd following things:
i'm having issues getting started loop. suggestions on how approach this?
import arcpy arcpy.env.workspace = ".\\" outws = "stacked_images_folder" rasters in folder: band1 = band2 = band3 = band4 = band5 = arcpy.compositebands_management("band1.tif;band2.tif;band3.tif; band4.tif, band5.tif","stacked_img.tif")i'm trying figure out how script know move on new image after stacking 5 bands. need sort images separate folders before beginning, or there work-around, e.g. code knows move on next image after reaching 5 bands?
you don't need loop if rasters in same folder:
import arcpy wd="y:/" #have directory rasters located arcpy.env.workspace = wd raster_list=arcpy.listrasters("", "tif") arcpy.compositebands_management(raster_list,"stacked_img.tif") #will save output on same folder specified above. if want save new subdir:
import os outws = wd+"stacked_images_folder/" os.makedirs(outws) arcpy.compositebands_management(raster_list, outws + "stacked_img.tif") now if have multiple set of rasters merge in same folder have common starting file name, such img1-b1, img1-b2, etc, can make entire process work following simple implementation:
import arcpy image_names=["img" + str(s) s in range(1,143)] wd="y:/" #have directory rasters located arcpy.env.workspace = wd image_name in image_names: print image_name raster_list=arcpy.listrasters(image_name+"-*", "tif") import os outws = wd+"stacked_images_folder/" os.makedirs(outws) arcpy.compositebands_management(raster_list, outws + image_name+ "_stacked_img.tif")
Comments
Post a Comment