我可以使用一些關於如何處理Python腳本中的錯誤的建議。從閱讀本網站上的所有Python錯誤處理帖子所能獲得的信息是,您不能簡單地繞過for循環中的錯誤,並嘗試使用continue語句。相反,你必須直接處理每個錯誤。這是我遇到問題的地方。我附加了發生在for循環中間的錯誤消息。此外,我重視我的腳本,通過以下流程移動:錯誤處理Python arcpy腳本需要的建議
- 周圍發生光柵
- 地方多邊形
- 的平均中心點的一多邊形用點來識別特定的縣其 相應的光柵相關
- 夾根據所選擇的縣多邊形
如何incorporat光柵e將錯誤信息中的信息轉換爲除continue語句之外的try,以便腳本可以移動到列表中的下一個柵格,而不是在處理過程中停止?
# 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"