I m using ArcGis 10.4.1 and network analyst extension where i create a Route Analysis layer. The following code's part is used:
#add a depot as stop.
fieldMappingsStore = arcpy.na.NAClassFieldMappings(outNALayer, stopsLayerName)
fieldMappingsStore["RouteName"].mappedFieldName = "Group_ID" #correlates fields ie naStops attribute table with inStores attribute table
fig.1 stores attribute table
#add stops
fieldMappingsStops = arcpy.na.NAClassFieldMappings(outNALayer, stopsLayerName)
fieldMappingsStops["RouteName"].mappedFieldName = "Group_ID" #correlates fields ie naStops attribute table with inStores attribute table
fig.2 stops attribute table
#AddLocations_na
arcpy.na.AddLocations(outNALayer, stopsLayerName, inDepots, fieldMappingsStore,................)
arcpy.na.AddLocations(outNALayer, stopsLayerName, inOrders, fieldMappingsStops,.................)
Apparently something is wrong with the above approach because the route layer is solved i get the following, where we can see that the first location for RouteName 1012 has SourceOID =-1 .
fig.3 Route Analysis layer stops attribute table
I don want want to use VRP because it is slower. Do i have to change my approach and merge the two shapefiles(stores and stops) or i can still use the above approach?
Solved! Go to Solution.
Hello sotokan80. The problem here actually has nothing to do with field mapping. Your field mapping looks fine (though you actually only need one field mapping object that you can use for both input tables).
When you see a -1 for SourceOID and the icon with a ? on it, this means that the stop is unlocated. Note that the Status field shows a status of 1, which means "Not located". (Status 0 means "OK".) For some reason, when you ran Add Locations, it could not determine the network location of that particular stop. The stop is probably far away from the network or something like that. Perhaps the lat/long of the original point are incorrect, or perhaps the search distance you've used as an option in Add Locations is too small.
Hello sotokan80. The problem here actually has nothing to do with field mapping. Your field mapping looks fine (though you actually only need one field mapping object that you can use for both input tables).
When you see a -1 for SourceOID and the icon with a ? on it, this means that the stop is unlocated. Note that the Status field shows a status of 1, which means "Not located". (Status 0 means "OK".) For some reason, when you ran Add Locations, it could not determine the network location of that particular stop. The stop is probably far away from the network or something like that. Perhaps the lat/long of the original point are incorrect, or perhaps the search distance you've used as an option in Add Locations is too small.
Thank you for your reply. Basicaly both store locations have the same coordinates. To be more specific i have one depot with name 101 and i want to create two routes for that depot 1011 and 1012 respectively. So i m copying the first row from depots shp and inserting that as a new row in the same .shp file naming the first depot as 1011 and the last as 1012. Maybe through that copy paste procedure the coordinates for the clone depot become "unreadable".
Is there any way to avoid doing that, by creating those two routes (1011&1012) without having two create two different depots and simply use one with RouteName 101?
The easiest thing might be to do this: In your original depot shapefile, add fields for RouteName1 and RouteName2, then use the Field Calculator to make them be 1011 and 1012, etc.
In your python script, do Add Locations once to add the depots the first time, and use field mapping to map RouteName1 to the RouteName Stops property. Then, do Add Locations again to add the depots a second time, this time mapping RouteName2 to the RouteName Stops property.