AnsweredAssumed Answered

Add first and last stop in Route Solver

Question asked by sotriant on Jan 19, 2018
Latest reply on Jan 23, 2018 by sotriant

I m using ArcGIS 10.4.1 and NetworkAnalyst. The following part of code is used in order to solve a route layer. i am using the same starting and ending point. It works ok if i only have one route. But if i have more than one routes it doesn't work. 

 

fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, stopsLayerName)

fieldMappings["RouteName"].mappedFieldName = "Group_ID"

 

#Add locations as Stops. T

 

#ADD FIRST STOP 
arcpy.na.AddLocations(outNALayer, stopsLayerName, inStops_1, fieldMappings1, "300 meters", "FID", [["roadNetwork_ND", "MIDDLE"], ["roadNetwork_ND_Junctions", "NONE"]], "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "", "", "")

 

arcpy.na.AddLocations(outNALayer, stopsLayerName, inStops_2, fieldMappings, "300 meters", "FID", [["roadNetwork_ND", "SHAPE"], ["roadNetwork_ND_Junctions", "NONE"]], "", "APPEND", "SNAP", "", "", "")

 

#ADD LAST STOP 

arcpy.na.AddLocations(outNALayer, stopsLayerName, inStops_1, fieldMappings1, "300 meters", "FID", [["roadNetwork_ND", "MIDDLE"], ["roadNetwork_ND_Junctions", "NONE"]], "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "", "", "")

#Solve the route layer.
arcpy.na.Solve(outNALayer)

 

 

FYI The solved routes

 

the stops attribute table

 

the depots attribute table

 

 

Do you have any suggestions for what should i do to adapt my code so that all the routes start and finish at the same point, (a company's depot)?

Outcomes