方向 (网络分析)
摘要
根据包含路径的网络分析图层生成方向信息。方向信息将写入到 XML 格式文件或文本格式文件中。
用法
-
如果该工具没有有效的结果,它将对网络分析图层进行求解。因此,在生成方向之前无需对网络分析图层求解。
-
可通过 ArcGIS 安装文件夹中的可用样式表将包含方向的输出 XML 文件转换为格式正确的 HTML 文件。例如,XML 格式的方向输出可通过样式表 Dir2WebDocument.xsl 或 Dir2PlainText.xsl(通常位于 C:\Program Files\ArcGIS\Desktop10.0\NetworkAnalyst\Directions\Styles 中)分别转换为 HTML 文件或文本文件。请注意,您将需要一个自定义工具,才能通过样式表将 XML 文件转换为 HTML 文件。
语法
Directions_na (in_network_analysis_layer, file_type, out_directions_file, report_units, {report_time}, {time_attribute})
参数 | 说明 | 数据类型 |
in_network_analysis_layer |
生成方向所依据的网络分析图层。只能针对“路径”、“最近设施点”和“多路径配送”网络分析图层生成方向。 | Network Analyst Layer |
file_type |
输出方向文件的格式。
| String |
out_directions_file |
将写入的方向文件的完整路径名。 | File |
report_units |
指定在方向文件中报告长度信息时所使用的线性单位。例如,即使阻抗的单位是米,您也可以使用英里显示方向。 | String |
report_time (可选) |
| Boolean |
time_attribute (可选) |
用于提供方向中的行驶时间且基于时间的成本属性。输入网络分析图层所使用的网络数据集中必须存在成本属性。 | String |
代码示例
方向示例 1(Python 窗口)
使用所有参数执行“方向”工具。
import arcpy arcpy.Directions_na("Route","TEXT","C:/temp/Route_Directions.txt","Miles", "REPORT_TIME","Minutes")
方向示例 2(工作流)
以下独立 Python 脚本演示了如何使用“方向”工具在文本文件中为路径生成驾车方向。
# Name: Directions_Workflow.py # Description: Generate driving directions in a text file for a route that # visits the store locations in the best sequence that minimizes # the total travel time # 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 = "StoreRoute" impedanceAttribute = "TravelTime" startLocation = "Analysis/DistributionCenter" storeLocations = "Analysis/Stores" fieldMappings = "Name Name #; Attr_TravelTime ServiceTime #" outDirectionsFile = "C:/data/output" + "/" + outNALayer + "Directions.txt" outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr" #Create a new route layer. The route starts at the distribution center and #takes the best sequence to visit the store locations. arcpy.MakeRouteLayer_na(inNetworkDataset,outNALayer,impedanceAttribute, "FIND_BEST_ORDER","PRESERVE_FIRST","",['Meters'], "NO_UTURNS",start_date_time="8 AM") #Load the distribution center as the start location using default field #mappings and search tolerance arcpy.AddLocations_na(outNALayer,"Stops",startLocation,"","") #Load the store locations as stops. Make sure the store locations are #appended to the Stops sublayer which already contains the distribution #center location. Map the Attr_TravelTime property from the ServiceTime #field so that the total travel time for the route will also contain the #service time arcpy.AddLocations_na(outNALayer,"Stops",storeLocations,fieldMappings,"","", "","","APPEND") #Generate driving directions in a text file arcpy.Directions_na(outNALayer,"TEXT",outDirectionsFile,"Miles", "REPORT_TIME","TravelTime") #Save the solved na layer as a layer file on disk using 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)
环境
相关主题
7/10/2012