AnsweredAssumed Answered

mosaicking only certain files within a folder using Python loop

Question asked by kgokkaya on Jun 18, 2016
Latest reply on Jun 27, 2016 by kgokkaya

I have a folder with filenames bio1_36.tif, bio1_37.tif, bio2_36_tif, bio2_37.tif, and so on. There are 19 bio variables and 36 and 37 at the end refer to the tile numbers. My goal is to mosaic the two tiles for each variable, clip to the size of a polygon layer called “Katanga” and convert the final output to ascii format. I’ve been using the code below however this will only generate the correct output if the two tiles for the same bio variable are specified in the code or these two files are the only input in the workspace folder.

How can I do the above procedure in a recursive manner for each bio variable, i.e. setting up a loop?

This way I don’t have to create separate folders for each bio variable or specify them in the code.

I am new to Python.

Below is the code I’ve been using (note: "test" folder only contains one bio variable with the two tiles):

import arcpy
from arcpy import env
from import*
import time

= time.clock()
.workspace = "G:/Eck_health_disease/spatial data/WorldClimate data/test"
.env.overwriteOutput = True
ImgList = arcpy.ListRasters()
print "Processing Mosaic"
print "Number of tiles to be Mosaicked:" + str(len(ImgList))
.MosaicToNewRaster_management(ImgList, env.workspace, "bio1_mos.tif",  pixel_type="32_BIT_FLOAT", cellsize="", number_of_bands="1", mosaic_method="", mosaic_colormap_mode="MATCH")
Katanga_poly = "G:/Eck_health_disease/spatial data/COD_adm_shp/DRC_Katanga.shp"
.Clip_management("bio1_mos.tif","21.7447528839 -13.4556760785 30.7780862172 -4.99734274513", "bio1_mos_Kat.tif", Katanga_poly, "#", "ClippingGeometry", "MAINTAIN_EXTENT")
.RasterToASCII_conversion("bio1_mos_Kat.tif", "bio1_mos_Kat.asc")
print "Task Completed!"
print time.clock() - start_time, "seconds"

Any help would be appreciated. Thank you!