AnsweredAssumed Answered

merge rasters Mosaic to New Raster

Question asked by lpalao on Dec 3, 2014
Latest reply on Dec 3, 2014 by Dalshearer

Hi Python Users,

 

I got stuck with my code trying to merge modis rasters (in tiff format) using Mosaic to New Raster. Any help will be much appreciated.

 

I have  time series NDVI rasters from MODIS data for 2014 for two tiles located in separate directory. What I would like to achieve is to automate the merging of the times series NDVI rasters using the Mosaic to New Raster tool in arcpy.

 

MOD_h26v06_2014001_ndvi.tif merged with MOD_h27v06_2014001.tif

 

.

 

.

 

.

 

MOD_h26v06_2014297_ndvi.tif merged with MOD_h27v06_2014297.tif

 

Any help/suggestion is very much appreciated.

 

Below is the code that I am working on.

 

Thanks,

 

-Leo

 

import arcpy, os, sys
from arcpy import env
from arcpy.sa import *
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")

raster1 = 'path/toRaster1'
arcpy.env.workspace = raster1
tile1 = [os.path.join(raster1, l) for l in arcpy.ListRasters("*2014*", "TIF")]

raster2 = 'path/toRaster2'
arcpy.env.workspace = raster2
tile2 = [os.path.join(raster2, r) for r in arcpy.ListRasters("*2014*", "TIF")]

out_ws = 'path/Out_rast'

# (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"
    mosaic = arcpy.MosaicToNewRaster_management(Raster(tile1[h]);Raster(tile2[h]), out_ws, filename, "", "16_BIT_SIGNED", "", "1", "LAST","FIRST")
    print mosaic

Outcomes