Hello!
I've having trouble setting the correct parameters to return a route that follows the shape of my network.
In the screenshot below, the thin grey lines are my road network, the green line is the shape that's generated when I solve for a route using the ArcGIS Pro tools and the purple line is the shape that's returned when I solve for the same route using the Network Analyst python module.
The relevant parts of my code are below. Almost all the parameters are left default, except that I've set the travel mode to "Walking" (I've tried different travel modes, they all return a funky line) and I've made sure to set the route shape type to "True Shape".
arcpy.nax.MakeNetworkDatasetLayer(oc_network_dataset, nd_layer_name)
nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes["Walking"]
route = arcpy.nax.Route(nd_layer_name)
route.travelMode = travel_mode
route.routeShapeType = arcpy.nax.RouteShapeType.TrueShape
stopsCur = route.insertCursor(arcpy.nax.RouteInputDataType.Stops, ["Name", "SHAPE@"], append = False)
....
stopsCur.insertRow([on_from, row2[1]])
....
stopsCur.insertRow([on_from, row3[1]])
result = route.solve()
if result.solveSucceeded:
with result.searchCursor(arcpy.nax.RouteOutputDataType.Routes, ["SHAPE@"]) as resultCursor:
for r in resultCursor:
insertCursor.insertRow('Routed from UL Intersection points', r[0]))
Is there a parameter on the Route that I'm missing? Or am I not handling the results correctly?
Thank you!
Jill
This definitely looks strange.
Your code looks fine to me.
What I can't determine from your screenshot is whether there are edges in your network underneath that zig-zaggy purple line. Are there? Or is the line just completely different from the underlying features in the network? In other words, is the purple route following SOME kind of streets, or is it just generating a wacky geometry that has nothing to do with the underlying network?
Since I really have no idea what might be causing this, here are some questions and things to check that might lead somewhere:
This definitely seems like a strange issue, and if none of these questions lead anywhere, you might be best served by calling Esri Support or Support for the distributor in your country. They can look at your workflow in detail and try to identify the problem.
@MelindaMorang, thank you for your detailed reply!
I went through all of your suggestions and was still not able to identify the issue.
My original script looped through records, parsing a text field into two addresses, geocoding the addresses and then generating a route between them. The output was a polyline feature class of the routes.
What I ended up doing is modifying the script to output the addresses as points. I then import those into my route layer as stops and execute all of the routes at once using the Pro tools. All of the routes produced by this workflow follow the true shape of the road network.
This works for my purposes. If it comes up again and I can't work around it I will reach out to Support.
Thanks again!