nonexistent travel modes in the network dataset makes me unable to do python coding

5263
13
Jump to solution
07-09-2021 05:23 PM
Labels (1)
zhongying_gan
New Contributor III

Hello. I'm using arcgis pro. I try to use Python to write codes to perform closest facility analysis under the network analyst tool. I need to set the travel modes. The following website provides the sample codes to update travel modes through python:https://pro.arcgis.com/en/pro-app/latest/arcpy/network-analyst/travelmode.htm

If you look at the screenshot, the mode is gray at the top left corner. When I perform analyses in ArcGIS Pro by clicking buttons, I would go to travel settings and change the impedance. That lets me to choose whether I want to use distance or time to perform optimization. 

The sample codes from https://pro.arcgis.com/en/pro-app/latest/arcpy/network-analyst/travelmode.htm that I use are the following:

import arcpy

network = r"C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
# Get all travel modes from the network dataset
travel_modes = arcpy.na.GetTravelModes(network)


# Print the impedance attribute and restrictions used for each travel mode
for travel_mode_name in travel_modes: travel_mode = travel_modes[travel_mode_name] print(travel_mode_name)
print("Impedance:", travel_mode.impedance)
print(
"Restrictions:", ", ".join(travel_mode.restrictions)) print("")

 

According to the codes, to set the impedance, I have to use travel_mode.impedance. However, the travel_model I get using "travel_modes = arcpy.na.GetTravelModes(network)" is {}, which is blank. 

Can anyone tell me how I could set impedance through python even if the travel modes for my network data set is an empty set? Thank you.

0 Kudos
2 Solutions

Accepted Solutions
MelindaMorang
Esri Regular Contributor

The recommended way to do Closest Facility analysis in Python in Pro is to use the Closest Facility python solver object.

Here is some documentation about network analysis with python generally.

Here is some documentation about the Closest Facility python object specifically.

However, in order to do an analysis that way, your network dataset does need to have at least one travel mode, so you need to figure out how to create one for your network dataset. If your network dataset is a licensed non-editable network dataset, I believe you should be able to create travel modes anyway. That functionality should be available.  However, it sounds like something strange has happened and caused your network to be read only for some other reason. I'm not sure how to resolve that issue, but maybe Esri Support can help.

View solution in original post

MelindaMorang
Esri Regular Contributor

Ohhhhhh, it's because it's a shapefile network dataset. Shapefile network datasets are not editable in ArcGIS Pro. Shapefile is an older format we are trying to move users away from. A file geodatabase network dataset is preferred and fully compatible with Pro and ArcMap.

 

If you have ArcMap, you might be able to add travel modes to the shapefile network there and then use them in Pro. I'm not really sure if that works, though.

View solution in original post

13 Replies
DanPatterson
MVP Esteemed Contributor

Does the newer nax module return the same issue?

NetworkDataset—ArcGIS Pro | Documentation

check travelModes under Properties for the network template you are working with


... sort of retired...
zhongying_gan
New Contributor III

Hello,

Thank you so much for pointing me to the newer nax module. I've used the command arcpy.nax.GetTravelModes on my local network dataset, but it still returns {}. I have checked the properties of my local network dataset as you suggested. Under the "Travel Attributes" section of my network dataset, there are no travel modes, only costs (properties_localnetwork.png). I checked the San Francisco network dataset that is included in the arcgis pro tutorial, and there are travel modes (properties_tutorial.png). I tried to add a new travel mode to my own network dataset so that I can have a travel mode, following the instructions on https://pro.arcgis.com/en/pro-app/latest/help/analysis/networks/create-travel-mode.htm. However, my network dataset is read-only (properties_read_only.png). I tried to go to the properties of the network dataset and uncheck the box of "Read-only", but the next time I open the file, the "Read-only" is checked again (read_only.png). Do you know how I could edit my network dataset?

I really don't know how I could perform closet facility analysis using Python now that there's no travel mode in my network dataset, and that I cannot create a new travel mode. If you could offer me some thoughts, I would really appreciate it.

 

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

I have move the threads to ArcGIS Network Analyst Questions.

You will have better luck getting a fuller response here than in the ArcGIS Pro or Python questions sections.


... sort of retired...
MelindaMorang
Esri Regular Contributor

The recommended way to do Closest Facility analysis in Python in Pro is to use the Closest Facility python solver object.

Here is some documentation about network analysis with python generally.

Here is some documentation about the Closest Facility python object specifically.

However, in order to do an analysis that way, your network dataset does need to have at least one travel mode, so you need to figure out how to create one for your network dataset. If your network dataset is a licensed non-editable network dataset, I believe you should be able to create travel modes anyway. That functionality should be available.  However, it sounds like something strange has happened and caused your network to be read only for some other reason. I'm not sure how to resolve that issue, but maybe Esri Support can help.

zhongying_gan
New Contributor III

Thank you so much for your reply. The network dataset I'm using is the following: https://apps.gis.ucla.edu/geodata/dataset/los-angeles-network-data. I just noticed that it's supposed to be used in ArcMap instead of ArcGIS Pro. Do you think maybe this has something to do with the issue I'm encountering? However, I'm able to use this network dataset in ArcGIS Pro if I just use network analyst through clicking buttons instead of writing python codes. The attached screenshot is the network dataset in the catalog pane.

I would really appreciate it if you could offer some insights. Thank you.

0 Kudos
MelindaMorang
Esri Regular Contributor

Ohhhhhh, it's because it's a shapefile network dataset. Shapefile network datasets are not editable in ArcGIS Pro. Shapefile is an older format we are trying to move users away from. A file geodatabase network dataset is preferred and fully compatible with Pro and ArcMap.

 

If you have ArcMap, you might be able to add travel modes to the shapefile network there and then use them in Pro. I'm not really sure if that works, though.

zhongying_gan
New Contributor III

Thank you so much for your reply. I opened ArcMap and tried to add travel modes using the instructions in the following link: https://desktop.arcgis.com/en/arcmap/latest/extensions/network-analyst/travel-modes-steps.htm. However, it doesn't allow me to do so (the screenshot is attached). May I ask whether you have any insights on this, or if you could point me to a specific sub-forum under Esri community where I may have the best chance to get an answer? Thank you so much. 

0 Kudos
MelindaMorang
Esri Regular Contributor

You are in the right place to get help with this problem. The issue is that shapefile networks just aren't well supported with newer functionality.

 

Here is a tutorial that shows you how to create a file geodatabase network dataset in Pro: https://pro.arcgis.com/en/pro-app/latest/help/analysis/networks/how-to-create-a-usable-network-datas... You may be able to use the street data from your shapefile network dataset if you copy the shapefile into a file geodatabase feature dataset. Try using Feature class To Feature Class or Copy Features.

zhongying_gan
New Contributor III

Thank you so much for pointing me to "Feature class To Feature Class" and "Copy Features". However, I am not able to export the network dataset into a geodatabase. There are three elements in my network dataset: two shp-files and one nd-file (network_dataset.png). However, no matter I use "Feature class To Feature Class" or "Copy Features", I am only able to get the two shp-files into the geodatabase. I am not able to get the network dataset into the geodatabase (feature class to feature class.png and copy features.png). I was wondering whether there's any specific way to export a nd-file into the geodatabase. Thank you.

0 Kudos