Select to view content in your preferred language

Route solve not returning true shape

198
2
06-11-2024 08:45 AM
JillianStanford
Occasional Contributor III

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.

JillianStanford_0-1717697800246.png

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

Tags (1)
0 Kudos
2 Replies
MelindaMorang
Esri Regular Contributor

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:

  • Does your travel mode (any of the ones you've used) have a simplification tolerance set, and what is it?
  • Is your network dataset built?  Have you edited the geometry or settings since the last time you built it?  (The General page on the network dataset properties will tell you if it's built.)
  • Are you 100% sure that the route you created using the Pro UI was using the same network that your script is using?  Did you accidentally use ArcGIS Online as the network data source for the layer in the UI?
  • If you call export() in your script to export the output route to a feature class, does it still look strange?  Maybe the problem is in the insertCursor.

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.

JillianStanford
Occasional Contributor III

@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!

0 Kudos