Be able to create network analyst travel mode with Python

1596
11
09-24-2024 09:16 AM
d484648
Occasional Contributor

Create the necessary methods and classes to support defining a network dataset travel mode with Python

11 Comments
MelindaMorang
Status changed to: Needs Clarification

Hello.  Thanks for submitting an idea!

You can create a travel mode in Python using the arcpy.nax.TravelMode() class as documented here: https://pro.arcgis.com/en/pro-app/latest/arcpy/network-analyst/travelmode-nax.htm.  Does this serve your needs?

The only thing this cannot do is save the travel mode permanently to the network dataset.  Is that the functionality you're asking for?

d484648

Thanks for the link. I'll take a look at it, but in the long term I'd like to save the travel mode permanently to the dataset instead of having to recreate it every time I want to use it.

MelindaMorang

Okay.  Can you tell us more about your desired workflow?  Why do you want to create a travel mode in Python and save it permanently to the network dataset?  (This doesn't sound like an unreasonable request, but I need to better understand your needs to prioritize this enhancement and determine whether some existing workflow could meet your needs.)

PamT
by

This thread is a few months old but I'm running into a similar issue. I have a workflow where I need to create a new Network Dataset on the fly based on a new set of routes, then run a closest facility analysis. Currently, the Create Network Dataset function does not make a default travel mode so I cannot create the Closest Facility dataset without using a template dataset which I'd like to avoid since several different organizations may be using this tool.

MelindaMorang

Thanks for the input, @PamT.  That's an interesting use case, and I understand the problem.  However, I'd still like to understand how you expect to use this workflow effectively.  When you run the Create Network Dataset tool, it creates a very simple network that has only a length attribute based on the shape length of the edge sources.  Is this cost attribute sufficient for your needs?  I suppose there are some cases where this would be sufficient, but usually people need to adjust their cost attributes to their needs before the network is usable, so even if we gave you the ability to add travel modes, the network might still be useless.

PamT
by

@MelindaMorang - Our use case is very simple. We're trying to find possible paths from a point to any intersection that meets a certain criteria. Nothing fancy at all that requires extra configuration so the default distance attribute is sufficient for this. For other reasons we may have to go back to using the older Legacy NA module instead of the newer NAX module which would also solve this problem.

MelindaMorang

Thanks @PamT.  That does make sense.

For your use case (since we're unlikely to be able to add this functionality quickly), you might be able to use Python's networkx package to construct a graph from your network dataset and then use one of the many graph search algorithms in that package to get the results you need.

Here is a sample script that creates a networkx graph from a network dataset using the nax NetworkDataset class.  Not exactly what you need, but maybe enough to get you started.

Using a layer-based workflow with arcpy.na, as you suggested, is also an option.

MelindaMorang

One further question @PamT.  You said you don't want to use a network dataset template, but why wouldn't that work for you?  If you don't need any complicated cost or restriction attributes, then the template will be very simple and won't require a consistent schema in the source feature classes.  As long as the inputs have the same feature class names, it should just work fine.  Or is enforcing the feature class names too much for your multiple organizations?

PamT
by

@MelindaMorang - The template is just one extra piece of data that has to be attached to the script that can get misplaced when transferring from organization to organization. The python toolbox can be self-contained, if needed, with an embedded script.

MDKaller

@MelindaMorang I recently installed ArcGIS Pro 3.4, and started to updated the network dataset I download from the local government GIS site.  Then, I created a travel mode for buses and attempted to create a "Oneway" restriction.  The attribute field uses numbers in place of text (0 = Two-Way), 1= FT, and 2=TF).  Upon opening the Field Script Evaluator Properties window, two things pop out.  First, the parcer only accepts Python instead of VBScript, and second of "Result" you now have "Value" which is rather confusing to me.  So I do my best to convert the code to Python.  But, after assigning the restriction, building the network and running the route builder, I get an error message, saying my stops are unlocated and cannot be map.  When I uncheck the "Oneway" restrictor, the route is created, though not as I like.  Any asistance would be appreciated.

 arcgis 34 network route error.jpg

 

field script evaluator properties arcgis 34.jpg