I have many hundreds of GeoTiff files to mosaic. The problem is that they are stored in a sub-directory structure whereby I need to traverse down into each sub-directory, mosaic all rasters in that location, and then go back up and down into all the other sub-directories sequentially to perform the same action. Some example directories would appear as follows:
c:\dem\250k\001 (do all rasters here)
............. \002 (do all rasters here)
............. \003 (do all rasters here)
I found the following Python snippet on the forum, but it finds and mosaics all rasters in all sub-directories to a single output layer. I need to find a way to "walk" into the sub-directories and output a single output for each. Thanks.
import arcpy
import os
workspace = r"c:\dem\250k"
arcpy.CheckOutExtension("Spatial")
rasters = []
walk = arcpy.da.Walk(workspace, topdown=True, datatype="RasterDataset")
for dirpath, dirnames, filenames in walk:
dirpaths.append(os.path.join(dirpath, dirnames)
for filename in filenames:
rasters.append(os.path.join(dirpath, filename))
ras_list = ";".join(rasters)
arcpy.MosaicToNewRaster_management(ras_list,workspace,
"test.tif", "", "16_BIT_SIGNED", "", "1", "LAST")
# return SA license
arcpy.CheckInExtension("Spatial")