You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在ArcMap中屏蔽Python警告以避免运行崩溃?

ArcMap 10.3.1中arcpy.Solve_na大量警告引发崩溃问题

在ArcMap 10.3.1环境下,使用arcpy包计算OD Cost Matrix时,运行arcpy.Solve_na函数会导致Python控制台输出大量警告信息,当警告行数超过3万行后,ArcMap会直接崩溃,必须关闭软件。

以下是相关代码、警告说明及尝试过的无效方法:

代码

POI = r"...path\poi"
other_Pt = r"...path\poi"
# Local variables:
TP_pi1_Layer1 = "TP_pi1_Layer1"

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(POI, TP_pi1_Layer1, Expression_mrt, "", "OBJECTID OBJECTID HIDDEN NONE;Shape Shape HIDDEN NONE;Name Name VISIBLE NONE;City City HIDDEN NONE;Town Town HIDDEN NONE;Level1 Level1 HIDDEN NONE;Level2 Level2 HIDDEN NONE;Level3 Level3 VISIBLE NONE;Id Id HIDDEN NONE")
    
# Local variables:
OD_Cost_Matrix = "OD Cost Matrix"
OD_Cost_Matrix__4_ = OD_Cost_Matrix
OD_Cost_Matrix__5_ = OD_Cost_Matrix__4_

# Process: Make OD Cost Matrix Layer
arcpy.MakeODCostMatrixLayer_na(NetworkDataset_ND, "OD Cost Matrix", "Length", "", "1", "", "ALLOW_UTURNS", "", "NO_HIERARCHY", "", "NO_LINES", "")

# Process: Add Locations
arcpy.AddLocations_na(OD_Cost_Matrix, "Origins", other_Pt, "", "200 Meters", "", "NetworkDataset_ND_Junctions NONE;Twn5000rc_polyline1 SHAPE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "NetworkDataset_ND_Junctions #;Twn5000rc_polyline1 #")

# Process: Add Locations
arcpy.AddLocations_na(OD_Cost_Matrix__4_, "Destinations", TP_pi1_Layer1, "Name Name #", "200 Meters", "", "NetworkDataset_ND_Junctions NONE;Twn5000rc_polyline1 SHAPE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "NetworkDataset_ND_Junctions #;Twn5000rc_polyline1 #")

# Process: Solve
arcpy.Solve_na(OD_Cost_Matrix__5_, "SKIP", "TERMINATE", "")

警告信息

这些警告不会阻止代码运行,但当警告行数超过3万行时,ArcMap会崩溃。

尝试过的无效方法

  • 方法一:
arcpy.SetLogHistory(False)
  • 方法二:
import warnings
def handle_warning():
    pass

warnings.showwarning = handle_warning
  • 方法三:
import warnings
warnings.filterwarnings("ignore")

请问有人解决过这个问题吗?如有不清楚的地方,请随时告知,感谢!

内容的提问来源于stack exchange,提问作者Chen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 13:05:36