How to add Travel Mode when creating a network dataset using arcpy

186
8
Jump to solution
03-31-2021 01:08 PM
KellyMcGee
New Contributor II

Software: ArcGIS Pro 2.7
In my standalone python script I am able to create a new network dataset in the new file geodatabase and build that network dataset.   How can I define a travel mode?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MelindaMorang
Esri Regular Contributor

You cannot define a travel mode or alter any other properties of the network dataset from standalone python. We just don't have python methods and classes in place to support that.

The Create Network Dataset tool creates a very basic bare-bones network with a single distance-based impedance attribute. If that's all you need, and you want to make a travel mode from that to use in your analysis, you can call arcpy.nax.TravelMode() and define it on the fly in your script.

However, I suspect it's more likely that you will need to customize your network in more detail to fit your needs. You have to do this manually in the ArcGIS Pro UI. Once you have done it once, you can create a template from that network using the Create Template From Network Dataset tool. If you need to recreate similar networks with the same schema and properties in your code workflow, you can use this xml template with the Create Network Dataset From Template tool. 

Hope this helps!

View solution in original post

0 Kudos
8 Replies
DanPatterson
MVP Notable Contributor

There is documentation for nax in the help files for python and arcpy

TravelMode—ArcGIS Pro | Documentation

A more general link for all classes and functions is...

What is the Network Analyst module (arcpy.nax)—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
KellyMcGee
New Contributor II

Thanks Dan, but been there read that.

0 Kudos
MelindaMorang
Esri Regular Contributor

You cannot define a travel mode or alter any other properties of the network dataset from standalone python. We just don't have python methods and classes in place to support that.

The Create Network Dataset tool creates a very basic bare-bones network with a single distance-based impedance attribute. If that's all you need, and you want to make a travel mode from that to use in your analysis, you can call arcpy.nax.TravelMode() and define it on the fly in your script.

However, I suspect it's more likely that you will need to customize your network in more detail to fit your needs. You have to do this manually in the ArcGIS Pro UI. Once you have done it once, you can create a template from that network using the Create Template From Network Dataset tool. If you need to recreate similar networks with the same schema and properties in your code workflow, you can use this xml template with the Create Network Dataset From Template tool. 

Hope this helps!

View solution in original post

0 Kudos
KellyMcGee
New Contributor II

 

Thanks Melinda.  I only need the single distance-based impedance attribute.  Do you have any examples on how to use arcpy.nax.TravelMode() ?  The help documentation only shows how to construct a new Travel Mode Object from an existing Travel Mode.  Would I just use newTravelMode = arcpy.nax.TravelMode()?

0 Kudos
MelindaMorang
Esri Regular Contributor

I don't have any specific examples. However, you can do exactly what you said. Just do:

tm = arcpy.nax.TravelMode()

Then  update the properties of the travel mode object, which are listed in the documentation.

tm.name = "My awesome travel mode"
# Auto-generated distance-based impedance attribute created by running
# Create Network Dataset
tm.impedance = "Length"

I think you can leave the other properties as default. Not sure. You will have to experiment with it.

0 Kudos
KellyMcGee
New Contributor II

Thanks, trying that now.

On  another note, you had sent me an email a little while back and unfortunately I think I must have deleted it by mistake.  It was regarding input on a survey I think.  You had helped me on another network problem at the 2019 UC.  If you still need input I would be happy to help, just resend me the email.

0 Kudos
KellyMcGee
New Contributor II

Well that failed.  Since I created the network dataset using newTravelMode = arcpy.nax.TravelMode(), there is no Travel Mode created so I am unable to use the newTravelMode = arcpy.nax.TravelMode() approach as it apparently needs an existing Travel Mode.
I will write code to modify the xml template so that I can complete this project.  However, since the Travel Mode is required, then we really need a way to create/modify it using arcpy, and not requiring one to exist already.  Sort of the Chicken or the egg problem.  I do appreciate the quick responses, and while it was not the answer I was hoping for, at least I can move forward and stop searching.  Have a great day.

0 Kudos
MelindaMorang
Esri Regular Contributor

Ah yes, sorry. You're right. The arcpy.nax solver objects do not allow you to instantiate them with a network dataset that does not have any travel modes, so unless the travel mode is actually a property of the network (which you cannot do), then you will not be able to use the solver objects. Your best bet is working with the network dataset templates.

0 Kudos