# Mosaic : Date 02, January, 2001 import arcpy, os years = [] months = [] ## either populate these manually or read in dates = [] try: for year in years: for month in months: for date in dates: workspace = arcpy.env.workspace = r"L:\MODIS_NDVI\TIF_files" + os.sep + year + os.sep + month + os.sep + date rasterList = arcpy.ListRasters("*","TIF") outLoc = workspace + os.sep + "mosaic.tif" arcpy.MosaicToNewRaster_management(rasterList, outLoc, "", "16_BIT_SIGNED", "", "1", "LAST", "FIRST") except: print "Mosiac failed." print arcpy.GetMessages()
import arcpy, osmonths = ['01_Jan','02_Feb'] dates = ['Date_01','Date_02']Fn=''for month in months: for date in dates: try: workspace = arcpy.env.workspace = r"M:\BD_MODIS_NDVI\PROJ_TIF\Test" + os.sep + month + os.sep + date+ os.sep rasterList = arcpy.ListRasters("*","TIF") for raster in rasterList: Fn= raster[0:7] # file names arcpy.MosaicToNewRaster_management(rasterList,workspace, Fn+".tif","", "16_BIT_SIGNED", "", "1", "LAST", "FIRST") except: print "Mosiac failed." print arcpy.GetMessages()
# Mosaic : Date 02, January, 2001 import arcpy, os rasts = [] try: workspace = arcpy.env.workspace = r"L:/MODIS_NDVI/TIF_files/2001" rasterList = arcpy.ListRasters("*","TIF") for raster in rasterList: rasts.append(raster.split(".")[0]) ## grabs the filename before first "." which is J year and appends to the list "rasts" del raster rastSet = set(rasts) ## make a set so unique (no duplicates) - result of one entry for each julian year for r in rastSet: ##iterate through set newList = [] for raster in rasterList: ## iterate through list of rasters again, and those that start with our value for r are appended to NewList. if raster.startswith(r): newList.append(raster) ## use this newList as you raster list for mosaic tool want to do the mosaic at this indentation level so it only does it for r = singlevalue del raster del newList except: print "Mosiac failed." print arcpy.GetMessages()
# Mosaic.py# Created on: 2013-03-02 17:51:39.00000# Description:## ---------------------------------------------------------------------------import arcpy, osFn=''rasts = []try: workspace = arcpy.env.workspace = r"M:\BD_MODIS_NDVI\PROJ_TIF\Test" rasterList = arcpy.ListRasters("*","TIF") for raster in rasterList: ## grabs the filename before first "." which is J year and appends to the list "rasts" rasts.append(raster.split(".")[0]) del raster ## make a set so unique (no duplicates) - result of one entry for each julian year rastSet = set(rasts) ##iterate through set for r in rastSet: newList = [] ## iterate through list of rasters again, and those that start with our value for r are appended to NewList. for raster in rasterList: if raster.startswith(r): newList.append(raster) for raster in newList: Fn= raster[0:7] # file names arcpy.MosaicToNewRaster_management(newList,workspace, Fn+".tif","", "16_BIT_SIGNED", "", "1", "LAST", "FIRST") ## use this newList as you raster list for mosaic tool # want to do the mosaic at this indentation level so it only does it for r = singlevalue del raster del newList except: print "Mosiac failed." print arcpy.GetMessages()
Could try something like this: # Mosaic : Date 02, January, 2001 import arcpy, os rasts = [] try: workspace = arcpy.env.workspace = r"L:/MODIS_NDVI/TIF_files/2001" rasterList = arcpy.ListRasters("*","TIF") for raster in rasterList: rasts.append(raster.split(".")[0]) ## grabs the filename before first "." which is J year and appends to the list "rasts" del raster rastSet = set(rasts) ## make a set so unique (no duplicates) - result of one entry for each julian year for r in rastSet: ##iterate through set newList = [] for raster in rasterList: ## iterate through list of rasters again, and those that start with our value for r are appended to NewList. if raster.startswith(r): newList.append(raster) ## use this newList as you raster list for mosaic tool want to do the mosaic at this indentation level so it only does it for r = singlevalue del raster del newList except: print "Mosiac failed." print arcpy.GetMessages() That should get you going,R_
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.