GetTravelModes

摘要

返回适用于网络数据源的出行模式对象的字典。 字典关键字是出行模式的名称,字典值是出行模式对象。

说明

可以在来自 ArcGIS EnterpriseArcGIS Online 门户或独立 ArcGIS Server 站点的本地数据集或网络数据源上定义一个或多个出行模式。 此函数可使用给定网络数据源的可用出行模式填充值列表。 例如,地理处理脚本工具可具有称为“出行模式”的字符串类型参数,在工具对话框中选择网络数据集后即可使用出行模式名称列表填充该参数。

语法

GetTravelModes (network_dataset_path)
参数说明数据类型
network_dataset_path

The network dataset or service from which to retrieve travel modes. The argument can be specified using one of the following options:

String
返回值
数据类型说明
Dictionary

关键字为出行模式名称且值是出行模式对象的字典。

代码示例

GetTravelModes 示例 1

在网络数据集中获取出行模式并打印步行时间出行模式。

import arcpy

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

ArcGIS Online 上创建出行模式名称列表。 可根据用户的帐户设置对这些名称进行本地化。

import arcpy

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

此示例展示了如何从网络获取出行模式并打印出行模式的部分属性。

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)

# 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("")
GetTravelModes 示例 4

此示例展示了如何从网络克隆出行模式、更新其属性并在分析中使用。

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)
# Construct a new TravelMode object from the existing Driving Time travel mode
new_travel_mode = arcpy.nax.TravelMode(travel_modes["Driving Time"])
# Update the useHierarchy property to turn hierarchy off, and update the name
new_travel_mode.name = "Driving Time without Hierarchy"
new_travel_mode.useHierarchy = "NO_HIERARCHY"
# Use the new travel mode object when constructing an OD cost matrix analysis
od_object = arcpy.nax.OriginDestinationCostMatrix(network)
od_object.travelMode = new_travel_mode
GetTravelModes 示例 5

以下代码示例演示了如何在独立 ArcGIS Server 站点上为路径选择服务调用 GetTravelModes

了解有关如何指定路径选择服务信息字典的详细信息

travel_modes = arcpy.nax.GetTravelModes(
    {
        "utilityUrl": f"https://mysite.mydomain.com/:6443/arcgis/rest/services/MyRouting/NetworkAnalysisUtilities/GPServer",
        "authenticationInfo": {
            "username": "my_username",
            "password": "my_password"
        }
    }
)