AnsweredAssumed Answered

Mosaic to new raster

Question asked by lpalao on Oct 17, 2014
Latest reply on Oct 20, 2014 by JSwain-esristaff



I want to mosaic a set of rasters in separate folders but I am stuck with my code. Basically, I have two sets of modis tiles located in two separate folders, and I want to create a mosaic dataset.




Folder 1 = mod_h26v06_2012001.tif, mod_h26v06_2012009.tif, mod_h26v06_2012017.tif, mod_h26v06_2012025.tif,......., mod_h26v06_2012361.tif

Folder 2 = mod_h27v06_2012001.tif, mod_h27v06_2012009.tif, mod_h27v06_2012017.tif, mod_h27v06_2012025.tif,......., mod_h27v06_2012361.tif


What I want to do:


mod_h26v06_2012001.tif merge with mod_h27v06_2012001.tif, ........, mod_h26v06_2012361.tif merge with mod_h27v06_2012361.tif


This is my initial code:

# import necessary modules of ArcGIS
import arcpy, os, sys
from arcpy import env
from import *

# this will overwrite output. Important in testing codes
arcpy.env.overwriteOutput = True

# activate the spatial analyst extention of ArcGIS

# specify your workspace. This is where raster is stored
raster1 = 'X:/raster_ws'
arcpy.env.workspace = raster1
h26v06 = [os.path.join(raster1, l) for l in arcpy.ListRasters("*2012*", "TIF")]

raster2 = 'X:/raster_ws'
arcpy.env.workspace = raster2
h27v06 = [os.path.join(raster2, r) for r in arcpy.ListRasters("*2012*", "TIF")]

out_ws = 'X:/output_ws/'

# (input rasters,outputloc,name w/ ext, coor, pixeltype, cellsize, #of bands
# mosaic method, mosaic color map)

for h in range(0,46):
    parse = l[18:25]
    filename = "modis_evi_" + parse + ".tif" #'modis_8day_2012_{:03d}.tif'.format(h+1)
    mosaic = arcpy.Mosaic_management(Raster(h26v06[h]);Raster(h27v06[h]), out_ws, filename, "", "16_BIT_SIGNED", "", "1", "LAST","FIRST")
    print mosaic


Any help is much appreciated.