# Import system modules import sys, string, os, arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create(9.3) gp.OverWriteOutput = 1 # Check out Spatial Analyst extension license gp.CheckOutExtension("Spatial") # Parameters Workspace01 = gp.GetParameterAsText(0) gp.AddMessage ("input Workspace01: " + Workspace01) #Workspace01 = r"C:\temp\test\Workspace1" Workspace02 = gp.GetParameterAsText(1) gp.AddMessage ("input Workspace02: " + Workspace02) #Workspace02 = r"C:\temp\test\Workspace2" OutWorkspace = gp.GetParameterAsText(2) gp.AddMessage ("output Workspace: " + output_Workspace) #OutWorkspace = r"C:\temp\test\outputwkspc" try: #Get the raster datasets in the input Workspace01 and loop through them from the start #I removed the messages for easier reading of the code. #Set the environment workspace to workspace one. gp.workspace is an environment variable and must be set befor listing data gp.workspace = Workspace01 InputRasters01 = gp.ListRasters()#This will list all the rasters in Workspace01 gp.workspace = Workspace02#change the workspace to the next workspace you wish to list data for. InputRasters02 = gp.ListRasters() iterInputRasters02 = iter(InputRasters02)#create an iterater for rasters02 so it may be incremented. for InputRaster in InputRasters01:#This will loop through your first list. #Becasue the workspace was changed to create the second list the path to the first list is no longer valid. So the script does not fail #we need to set the full path name to items in InputRasters01. fullInputRaster = Workspace01 + os.sep + InputRaster InputRaster02 = iterInputRasters02.next()#increment #Set the output table name nameRaster1 = gp.describe(fullInputRaster).baseName nameRaster2 = gp.describe(InputRaster02).baseName outRaster = OutWorkspace + os.sep + "mean" + InputRaster + ".tif"#create a tif with first raster name. Use a tif because the name could become too long for esri grid. InExpression = "MEAN(" + fullInputRaster + "," + InputRaster02 +")"#use the variable so the raster is updated for each SOMA call # Process: MapAlgebra gp.SingleOutputMapAlgebra_sa(InExpression, outRaster) except: gp.AddMessage(gp.GetMessages(2)) print gp.GetMessages(2)
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.