Skip To Content

GetTravelModes

Summary

Returns a dictionary of travel mode objects that are available with the network data source. The dictionary keys are the names of the travel modes, and the dictionary values are the travel mode objects.

Discussion

One or more travel modes can be defined on a local network dataset, or on a network datasource from an ArcGIS Enterprise or ArcGIS Online portal. This function can be used to populate a value list with the available travel modes given a network data source. For example, a geoprocessing script tool can have a parameter of type String called Travel Modes that can be populated with a list of travel mode names once a network dataset has been selected on the tool dialog box.

Syntax

GetTravelModes (network_dataset_path)
ParameterExplanationData Type
network_dataset_path

A variable that references the catalog path of a network dataset, a network dataset layer object, or the URL of a portal configured with the network analysis services.

The catalog path of a network dataset can be obtained from the dataSource property of a network dataset layer or a network analysis layer object. It can also be obtained from the catalogPath property of a network dataset Describe object.

String
Return Value
Data TypeExplanation
Dictionary

A dictionary whose keys are the travel mode names and values are the travel mode objects.

Code sample

GetTravelModes example 1

Get the travel modes in a network dataset and print the walking time travel mode.

import arcpy

nds = 'C:/Data/SanDiego.gdb/Transportation/Streets_ND'
travel_modes = arcpy.nax.GetTravelModes(nds)
print(travel_modes['Walking Time'])
GetTravelModes example 2

Create a modified version of a travel mode from the network dataset and use this in an origin destination cost matrix analysis.

import json
import arcpy

network = r"C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
# Get all travel modes from the network dataset
travel_modes = arcpy.nax.GetTravelModes(network)
# Get the Driving Distance travel mode
dd_travel_mode = travel_modes["Driving Distance"]
# Make a json representation of the travel mode
travel_mode_json = json.loads(str(dd_travel_mode))
# Modify the userHierarchy property to turn hierarchy off, and update the name
travel_mode_json["useHierarchy"] = False
travel_mode_json["name"] = "Driving Distance without Hierarchy"
# Create a new travel mode object from the modified json
new_travel_mode_object = arcpy.nax.TravelMode(json.dumps(travel_mode_json))
# Use the new travel mode object when constructing an OD cost matrix analysis
# We could also pass in the json directly without first converting it to an object
od_object = arcpy.nax.OriginDestinationCostMatrix(network)
od_object.travelMode = new_travel_mode_object
GetTravelModes example 3

Create a list of travel mode names on ArcGIS Online. The names could be localized, depending on the user's account setting.

import arcpy

travel_modes = arcpy.nax.GetTravelModes("https://www.arcgis.com/")
travel_mode_names = [travel_modes[mode].name for mode in travel_modes]