创建路径分析图层 (网络分析)
摘要
创建路径网络分析图层并设置其分析属性。路径分析图层可用于根据指定的网络成本确定一组网络位置之间的最佳路径。
用法
语法
| 参数 | 说明 | 数据类型 |
in_network_dataset |
将在其中执行路径分析的网络数据集。 | Network Dataset Layer |
out_network_analysis_layer |
要创建的路径网络分析图层的名称。 | String |
impedance_attribute |
分析过程中用作阻抗的成本属性。 | String |
find_best_order (可选) |
| Boolean |
ordering_type (可选) |
当使用 FIND_BEST_ORDER 时,将指定停靠点的顺序。
| String |
time_windows (可选) |
Specifies if time windows will be used at the stops.
| Boolean |
accumulate_attribute_name [accumulate_attribute_name,...] (可选) |
分析过程中要累积的成本属性的列表。这些累积属性仅供参考;求解程序仅使用阻抗属性参数所指定的成本属性来计算路径。 对于每个累积的成本属性,均会向求解程序所输出的路径中添加一个 Total_[阻抗] 属性。 | String |
UTurn_policy (可选) |
限制或允许停靠点间网络遍历过程中可能出现在交汇点处的 U 形转弯。
| String |
restriction_attribute_name [restriction_attribute_name,...] (可选) |
分析过程中要应用的约束属性的列表。 | String |
hierarchy (可选) |
如果未在用于执行分析的网络数据集中定义等级属性,该参数将不可用。在这种情况下,使用“#”作为参数值。 | Boolean |
hierarchy_settings (可选) |
旧版本:在版本 10 之前,可使用此参数将网络数据集中建立的默认等级范围更改为其他范围以用于分析。而版本 10 中不再支持此参数,并且应将其指定为空字符串。如果您要更改等级范围以进行分析,请更新网络数据集中的默认等级范围。 | Network Analyst Hierarchy Settings |
output_path_shape (可选) |
为分析所输出的路径要素指定形状类型。
无论选择何种输出 shape 类型,最佳路径始终由网络阻抗(而非欧氏距离)决定。这表示只是路径形状不同,而对网络进行的基础遍历则相同。 | String |
start_date_time (可选) |
指定路径的开始日期和时间。路径开始时间通常用于查找基于阻抗属性(随当日时间变化)的路径。例如,开始时间 9 AM 可用于查找被认为是高峰时段流量的路径。此参数的默认值为 8:00 AM。可将日期和时间指定为 10/21/05 10:30 AM。如果路径历时多天,则仅指定开始时间,然后使用当前日期。 可使用以下日期来指定一周中的每一天,而无需使用特定的日期。
求解结束后,在输出路径中填充路径的开始时间与结束时间。也会在生成指示时使用这些开始时间和结束时间。 仅当将基于时间的成本属性指定为阻抗属性时,此选项才有效。 | Date |
代码示例
仅使用必需参数执行此工具
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.MakeRouteLayer_na("Transportation/Streets_ND","WorkRoute","Minutes")
使用所有参数执行此工具
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.MakeRouteLayer_na("Transportation/Streets_ND","InspectionRoute","Minutes",
"FIND_BEST_ORDER","PRESERVE_BOTH","USE_TIMEWINDOWS",
["Meters","Minutes"],
"ALLOW_DEAD_ENDS_AND_INTERSECTIONS_ONLY",["Oneway"],
"USE_HIERARCHY","","TRUE_LINES_WITH_MEASURES",
"1/1/1900 9:00 AM")
以下独立 Python 脚本演示了如何使用 MakeRouteLayer 工具查找最佳路径以访问地理编码的停靠点位置。
# Name: MakeRouteLayer_Workflow.py
# Description: Find a best route to visit the stop locations and save the
# route to a layer file. The stop locations are geocoded from a
# text file containing the addresses.
# Requirements: Network Analyst Extension
#Import system modules
import arcpy
from arcpy import env
try:
#Check out the Network Analyst extension license
arcpy.CheckOutExtension("Network")
#Set environment settings
env.workspace = "C:/data/SanFrancisco.gdb"
env.overwriteOutput = True
#Set local variables
inNetworkDataset = "Transportation/Streets_ND"
outNALayer = "BestRoute"
impedanceAttribute = "TravelTime"
inAddressLocator = "SanFranciscoLocator"
inAddressTable = "C:/data/StopAddresses.csv"
inAddressFields = "Street Address VISIBLE NONE"
fieldMappings = "Name Address #"
outStops = "GeocodedStops"
outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr"
#Create a new Route layer. Once the route layer is created, it can be
#referenced using its name.
arcpy.MakeRouteLayer_na(inNetworkDataset, outNALayer, impedanceAttribute)
#Geocode the stop locations from a csv file containing the addresses.
#The Geocode Addresses tool can use a text or csv file as input table
#as long as the first line in the file contains the field names.
arcpy.GeocodeAddresses_geocoding(inAddressTable, inAddressLocator,
inAddressFields, outStops)
#Load the geocoded address locations as stop smapping the address field from
#geocoded stop features as Name property.
arcpy.AddLocations_na(outNALayer,"Stops", outStops, fieldMappings, "")
#Solve the route layer, ignore any invalid locations such as those that
#can not be geocoded
arcpy.Solve_na(outNALayer,"SKIP")
#Save the solved route layer as a layer file on disk with relative paths
arcpy.SaveToLayerFile_management(outNALayer,outLayerFile,"RELATIVE")
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)