Resumen
A read cursor for a solver result class, specific to an output type, that can be used to read rows directly from the output.
Debate
Instances of this class are not created directly. Instead, they are created by calling the searchCursor method on one of the solver result classes after solving a network analysis.
Muestra de código
Use the searchCursor method and a SolverResultSearchCursor object to retrieve the outputs of an analysis.
# 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("Solve failed")
print(result.solverMessages(arcpy.nax.MessageSeverity.All))