描述
特定于输出类型的求解程序结果类读取游标,可用于直接从输出读取行。
讨论
此类实例不是直接创建的, 而是在求解网络分析后,通过在一个求解程序结果类上调用 searchCursor 方法进行创建。
代码示例
使用 searchCursor 方法和 SolverResultSearchCursor 对象来检索分析的输出。
# An example showing how to use the searchCursor() method to access the output of an analysis
import arcpy
arcpy.CheckOutExtension("network")
nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_origins = "C:/data/io.gdb/Origins"
input_destinations = "C:/data/io.gdb/Destinations"
# Create a network dataset layer and get the desired travel mode for analysis
arcpy.nax.MakeNetworkDatasetLayer(nds, nd_layer_name)
nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes["Driving Time"]
# Instantiate a OriginDestinationCostMatrix solver object
odcm = arcpy.nax.OriginDestinationCostMatrix(nd_layer_name)
# Set properties
odcm.travelMode = travel_mode
odcm.timeUnits = arcpy.nax.TimeUnits.Minutes
odcm.distanceUnits = arcpy.nax.DistanceUnits.Miles
odcm.lineShapeType = arcpy.nax.LineShapeType.NoLine
# Load inputs
odcm.load(arcpy.nax.OriginDestinationCostMatrixInputDataType.Origins, input_origins)
odcm.load(arcpy.nax.OriginDestinationCostMatrixInputDataType.Destinations, input_destinations)
# Solve the analysis
result = odcm.solve()
# Print the OD cost matrix results
if result.solveSucceeded:
fields = ['OriginOID', 'DestinationOID', 'DestinationRank', 'Total_Time', 'Total_Distance']
for row in result.searchCursor(arcpy.nax.OriginDestinationCostMatrixOutputDataType.Lines, fields):
print(row)
else:
print("Solved failed")
print(result.solverMessages(arcpy.nax.MessageSeverity.All))