方向 (网络分析)

摘要

根据包含路径的网络分析图层生成方向信息。方向信息将写入到 XML 格式文件或文本格式文件中。

用法

语法

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

输出方向文件的格式。

  • XML将以 XML 文件的形式生成输出方向文件。除路径的方向字符串和长度及时间信息外,该文件还包含有关每个方向的行进策略类型和转弯角度的信息。如果希望采用自己的格式来显示方向,应使用 XML 格式。
  • TEXT将以简单文本文件的形式生成输出方向文件,其中包含路径的方向字符串和长度信息,另外还可包含路径的时间信息。
String
out_directions_file

将写入的方向文件的完整路径名。

File
report_units

指定在方向文件中报告长度信息时所使用的线性单位。例如,即使阻抗的单位是米,您也可以使用英里显示方向。

String
report_time
(可选)
  • NO_REPORT_TIME在方向文件中不报告行驶时间。
  • 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