Note that there are some explanatory texts on larger screens.

plurals
  1. POError handling advice needed for Python arcpy script
    text
    copied!<p>I could use some advice on how to handle errors in my Python script. From what I have been able to gather from reading all of the Python error handling posts on this site, is that you cannot simply bypass an error within a for loop with a try except continue statement. Instead, you have to handle each error directly. This is where I am having problems tying it all together. I have attached the error message that occured in the middle of a for loop. Additionally, I have attached my script which moves through the following workflow:</p> <ol> <li>place a polygon around the raster</li> <li>place a point on the mean center of the polygon</li> <li>use the point to identify a specific county associated with its corresponding raster</li> <li>clip the raster based on the selected county polygon</li> </ol> <p><strong>How do I incorporate information from the error message into a try except continue statement, so that the script can move to the next raster in the list rather than stopping in the middle of processing?</strong></p> <pre><code># Import arcpy module import arcpy from arcpy import env from arcpy.sa import * arcpy.CheckOutExtension("3D") # Set Over write arcpy.env.overwriteOutput = 1 # Set the workspace env.workspace = r"Z:\temp.gdb" outworkspace = r"Z:\location2\temp2.gdb" # Local variables: counties = r"Z:\temp.gdb\boundaries\Counties" counties_lyr = arcpy.MakeFeatureLayer_management(counties,"counties_lyr") # Get the list of rasters to process raster_list = arcpy.ListRasters("*_clp") print raster_list for raster in raster_list: # Define name and location for output raster name = outworkspace + "\\" + str(raster) # Process: Raster Domain arcpy.RasterDomain_3d(raster, "in_memory/temp", "POLYGON") # Process: Central Feature arcpy.MeanCenter_stats("in_memory/temp", "in_memory/temp1") # Process: Select Layer By Location arcpy.SelectLayerByLocation_management(counties_lyr, "intersect", "in_memory/temp1", "", "NEW_SELECTION") # Clip Raster arcpy.Clip_management(raster, "#", name,counties_lyr, "#", "ClippingGeometry") # Delete in_memory arcpy.Delete_management("in_memory") print "processing " + raster + " complete..." print "All processing is now finished" </code></pre> <p><img src="https://i.stack.imgur.com/Fq7ze.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload