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:

  1. 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") 
  2. 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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -