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

5638
13
Jump to solution
07-09-2021 05:23 PM
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
13 Replies
MelindaMorang
Esri Regular Contributor

That's correct. Feature Class To Feature Class and Copy Features do not work with network datasets. There is no way to convert or export a shapefile network dataset. You have to recreate it from scratch in a file geodatabase.  Here is the procedure:

  1. Create a new file geodatabase
  2. Create a new feature dataset within the file geodatabase in the spatial reference you want (you can even import the spatial reference from the shapefile to make sure it's the same)
  3. Run Feature Class To Feature Class or Copy Features to export the la_streets_clip_UTM.shp shapefile (which has the streets data) to a new feature class in the feature dataset.
  4. Use the Create Network Dataset tool to create a new network dataset in the feature dataset using that new street feature class as a source
  5. Manually configure all the network dataset properties to match the properties of the original shapefile network dataset. Depending on how complex your shapefile network is, this may take some work. I'm sorry there isn't an easier way.
  6. Run the Build Network tool to finalize the network. Address any build errors if needed, then test and validate your network.
0 Kudos
zhongying_gan
New Contributor III

Thank you for your detailed explanation. Now I'm following the steps in https://pro.arcgis.com/en/pro-app/latest/help/analysis/networks/how-to-create-a-usable-network-datas... to create a new network datasets after importing the two shapefiles into a geodatabase.

However, I encountered another problem. The sources of the original network dataset is la_streets_clip_UTM, and la_streets_clip_UTM_ND_Junctions (source in the original dataset.png). Therefore, I use these two sources to create a new network dataset called la_ND (create network dataset.png). However, a default junction file is automatically created, whose name is la_ND_Junctions. And I am unable to uncheck it through Add/Remove Sources (cannot remove default junction.png), nor am I able to delete it through the catalog pane. I was wondering how I should approach this issue. Thank you.

0 Kudos
MelindaMorang
Esri Regular Contributor

When you create and build a network dataset, the build process automatically generates a feature class of "system junctions". These are point features representing locations in the network where edges intersect. You should not edit or remove or interact with this auto-generated feature class. It's just there so everything else will work right.

In your old shapefile network, la_streets_clip_UTM_ND_Junctions is probably the auto-generated system junctions. Don't bother exporting that or using it to create your new network. Just leave it out. Then, when you run Build Network to build your new network, it will auto-generate a fresh system junctions feature class. This is the expected, correct behavior.

zhongying_gan
New Contributor III

Thank you. I just constructed a new network dataset from the original shapefile, and was also able to create travel modes. The new network dataset worked well in ArcGIS Pro. Thank you so much for your help along the way. I really appreciate it.

0 Kudos