applyTravelMode
汇总
用于访问路径网络分析图层的分析属性。 GetSolverProperties 函数用于从路径网络分析图层中获取 RouteSolverProperties 对象。
讨论
RouteSolverProperties 对象提供对路径网络分析图层中所有分析属性的读取和写入权限。该对象可用于修改路径分析图层的分析属性,并且相应的图层可重新求解以确定适合的结果。使用 创建路径分析图层 地理处理工具可创建新的路径图层。通过从新的路径图层获取 RouteSolverProperties 对象,可重新对现有图层进行后续分析,而无需每次分析都创建一个图层,以节省时间。
修改 RouteSolverProperties 对象的属性后,相应的图层可立即与其他函数和地理处理工具配合使用。无需刷新或更新图层,通过上述对象进行的修改便可生效。
语法
applyTravelMode()
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
accumulators (读取和写入) |
用于获取或设置累积为分析一部分的网络成本属性的列表。 空列表 |
String |
|
attributeParameters (读取和写入) |
用于获取或设置将在分析中使用的参数化属性。 该属性返回一个 Python 字典。 该字典关键字是由属性名称和参数名称这两个值组成的元组。 字典中每个项目的值均为参数值。 参数化的网络属性用于对属性值的某个动态方面进行建模。 例如,可使用某个参数对高度限制为 12 英尺的隧道进行建模。 在这种情况下,应将以英尺为单位的车辆高度指定为参数值。 如果车辆高度超过 12 英尺,此限制条件将评估为 尝试修改 请勿尝试修改
使用新的字典对象修改
如果网络分析图层没有参数化属性,则该属性将返回 |
Dictionary |
|
findBestSequence (读取和写入) |
控制是否重新排序停靠点以查找最佳路径。 以下是可能值列表:
|
String |
|
ignoreInvalidLocations (读取和写入) |
指定是否忽略无效的输入位置。 通常,如果无法 在网络上定位 ,则位置无效。 当无效位置被忽略时,求解程序将跳过它们并尝试使用剩余位置执行分析。
|
String |
|
impedance (读取和写入) |
用于获取或设置用作阻抗的网络成本属性。 当确定最佳路径时,该成本属性最小化。 |
String |
|
orderingType (读取和写入) |
控制当
|
String |
|
outputPathShape (读取和写入) |
用于获取或设置求解程序输出的路径要素的形状类型。 以下是可能值列表:
|
String |
|
restrictions (读取和写入) |
用于获取或设置适用于分析的约束属性的列表。 空列表 |
String |
|
solverName (只读) |
返回被用于获取求解程序属性对象的网络分析图层所引用的求解程序的名称。 从 |
String |
|
streetDirectionsProperties (读取和写入) |
为 |
Object |
|
timeOfDay (读取和写入) |
用于获取或设置路径开始日期和时间。 路径开始时间通常用于查找阻抗属性随当日时间变化的路径。 例如,开始时间 9 a.m. 可用于查找被认为是高峰时段流量的路径。 可以用值 可使用以下日期来指定一周中的每一天,而无需使用特定的日期:
例如,要指定路径从星期二 5:00 p.m. 开始,则请将值指定为
|
DateTime |
|
timeZoneUsage (读取和写入) |
指定
当求解一个跨多个时区的路径分析并设置起始时间时, |
String |
|
timeZoneUsageForTimeFields (读取和写入) |
指定输入数据中日期时间字段的时区,例如用于时间窗的字段。
|
String |
|
travelMode (只读) |
访问网络分析图层上设置为 |
Object |
|
uTurns (读取和写入) |
用于获取或设置策略,该策略指示求解程序如何管理停靠点之间的遍历网络期间所产生的交汇点处的 U 形转弯。 以下是可能值列表:
|
String |
|
useHierarchy (读取和写入) |
当执行分析时控制等级属性的使用。 以下是可能值列表:
|
String |
|
useTimeWindows (读取和写入) |
控制是否在停靠点处使用时间窗。 以下是可能值列表:
注:该属性已被维护以实现向后兼容性,但在 ArcGIS Pro 中被忽略。 如果时间窗口被填充,ArcGIS Pro 中的路径图层将始终使用时间窗口 |
String |
方法
applyTravelMode(travel_mode)
根据出行模式对象更新网络分析图层的分析属性。随后可对更新的网络分析图层进行求解以完成分析。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
travel_mode |
该变量引用一个源自网络数据集的出行模式对象。可通过调用 |
Object |
代码示例
此脚本显示如何在一天的两个时间找出一组停靠点间的最快路径。由于交通流量状况会不断发生变化,因此行程时间有所不同。此脚本说明如何只创建一个路径图层实例并使用 RouteSolverProperties 对象将 timeOfDay 属性改为所需结果。
旧版本:
GetNASublayer 函数用于调用网络分析图层的子图层。 该函数已在 ArcGIS Pro 2.7 中引入。 在以前的软件版本中,用于检索网络分析图层的子图层对象的最佳方法是使用网络分析 Layer 对象的 listLayers 方法,该方法将子图层名称用作通配符。
# Name: RouteSolverProperties_workflow_01.py
# Description: Find the fastest route at two different times of day. The travel
# time is different because of traffic conditions. Use the
# RouteSolverProperties object to update an existing Route layer
# before re-running the analysis.
# Requirements: Network Analyst extension
# Import system modules
import arcpy
from arcpy import env
import os
try:
# Set environment settings
output_dir = "C:/Data"
# The NA layer's data will be saved to the workspace specified here
env.workspace = os.path.join(output_dir, "Output.gdb")
env.overwriteOutput = True
# Set local variables
input_gdb = "C:/Data/SanFrancisco.gdb"
network = os.path.join(input_gdb, "Transportation", "Streets_ND")
stops = os.path.join(input_gdb, "Analysis", "Stores")
route_0830 = os.path.join(output_dir, "Output.gdb", "Route_MorningRush")
route_1100 = os.path.join(output_dir, "Output.gdb", "Route_MidMorning")
# Make a new route layer using travel time as impedance to determine fastest
# route
route_layer = arcpy.na.MakeRouteAnalysisLayer(network, "StoresRoute",
"Driving Time",
time_of_day="8:30 AM").getOutput(0)
# Get the network analysis class names from the route layer
na_classes = arcpy.na.GetNAClassNames(route_layer)
# Load stops
arcpy.na.AddLocations(route_layer, na_classes["Stops"], stops)
# Solve the route layer
arcpy.na.Solve(route_layer)
# Get the routes sublayer from the route layer
routes_sublayer = arcpy.na.GetNASublayer(route_layer, "Routes")
# Save the resulting route as a feature class. This route was solved at 8:30
# AM, morning rush hour.
arcpy.management.CopyFeatures(routes_sublayer, route_0830)
# Get the RouteSolverProperties object from the route layer to modify the
# timeOfDay property of the route layer.
solver_props = arcpy.na.GetSolverProperties(route_layer)
# Set the impedance property to "Meters" to determine the shortest route.
solver_props.timeOfDay = "11:00 AM"
# Re-solve the route layer
arcpy.na.Solve(route_layer)
# Save the resulting route as a feature class. This route was solved at 11:00
# AM, mid-morning when traffic is probably lighter.
arcpy.management.CopyFeatures(routes_sublayer, route_1100)
print("Script completed successfully")
except Exception as e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print("An error occured on line %i" % tb.tb_lineno)
print(str(e))
此脚本显示如何将 TruckingTime 出行模式应用到现有图层。
#Get the route layer object from a layer named "Route" in the map
doc = arcpy.mp.ArcGISProject('current')
map_obj = doc.listMaps()[0]
route_layer = map_obj.listLayers('Route')[0]
#Get the Trucking Time travel mode from the network dataset
desc = arcpy.Describe(route_layer)
travel_modes = arcpy.na.GetTravelModes(desc.network.catalogPath)
trucking_mode = travel_modes["Trucking Time"]
#Apply the travel mode to the analysis layer
solver_properties = arcpy.na.GetSolverProperties(route_layer)
solver_properties.applyTravelMode(trucking_mode)