I'm rather new to python so my code might be horrid but I had a question about executing scripts from ArcMap and performance involving several if statements.
The main objective is to create a toolbox with several different possible executions depending on the users input.
Essentially I have two options that I see!?! --- note there might be errors as I am simply writing an example code that represents what I am doing. At the moment, iterating through only 5 (6000x6000cells) rasters my code runs in hours that in my mind should not take more than one.
import arcpy arcpy.checkoutextension('spatial') def main(inputfolder,outputfolder,x,y): inputfolder = arcpy.env.workspace RasterList = arcpy.ListRasters() for RasterImage in RasterList: try: if 'True' in x: sa.Slope(.....) else: if 'True' in y: sa.Reclassify(....) else: RasterImage * 2 except Exception e: arcpy.GetMessages(e)
or is defining separate functions better? i.e.
def main(inputfolder,outputfolder,x,y): inputfolder = arcpy.env.workspace arcpy.ListRasters() if 'True' in x: x(inputfolder, outputfolder, RasterList) elif 'True' in y: y(inputfolder, outputfolder, RasterList) else: for RasterImage in RasterList: try: RasterImage *2 def x(inputfolder, outputfolder, RasterList) for RasterImage in RasterList: .... def y(inputfolder, outputfolder, RasterList) .....
Any help would be most appreciated!
Solved my problem. Thanks for all the responses and help.
The problem was not with my code but rather that a few of the datasets that I had been given were corrupt. Using a try: except: I was able to pass through those corrupt files (write an error log of those files) and later delete them.