AnsweredAssumed Answered

Mosaic raster files in a loop from all sub-directories in a directory

Question asked by zia207 on Jun 24, 2013
Latest reply on Jun 27, 2013 by rzufelt
Mosaic raster files in a loop from all sub-directories in a directory
I am trying to mosaic all tif files from a directory, it works fine for the files for a particular directory using following python code. I like to run this code in a loop to process data  for all other months (~/year/month/date). Structure of my input dir, sub directories like this:
L:/MODIS_NDVI/TIF_files/2001/ January /Date_01
~  /Date_02
L:/MODIS_NDVI/TIF_files/2001/ February /Date_01
~  /Date_02
Help will be appreciated.
Zia

# Mosaic:  Date 01, January, 2001
try:
    import arcpy
    arcpy.env.workspace =  r"L:/MODIS_NDVI/TIF_files/2001/ January /Date_01"
    rasterList = arcpy.ListRasters("*","TIF")
    outLoc = "H:\\ MODIS_NDVI \\MOSAIC_Files \\2001\\January\\"+ raster[9:-16]
    arcpy.MosaicToNewRaster_management(rasterList, outLoc + ".tif", "", "16_BIT_SIGNED", "", "1", "LAST", "FIRST")
except:
    print "Mosiac failed."
    print arcpy.GetMessages()

#  Mosaic : Date 02, January, 2001
try:
    import arcpy
    arcpy.env.workspace =  r"L:/MODIS_NDVI/TIF_files/2001/ January /Date_02"
    rasterList = arcpy.ListRasters("*","TIF")
    outLoc = "H:\\ MODIS_NDVI \\MOSAIC_Files \\2001\\January\\"+ raster[9:-16]
    arcpy.MosaicToNewRaster_management(rasterList, outLoc + ".tif", "", "16_BIT_SIGNED", "", "1", "LAST", "FIRST")
except:
    print "Mosiac failed."
    print arcpy.GetMessages()

Outcomes