方向 (Network Analyst)

摘要

根据包含路径的网络分析图层生成转弯方向。 可以将这些方向信息写入到文本、XML 或 HTML 格式的文件中。 如果提供适当的样式表,则可以将这些方向信息写入任何其他文件格式。

使用情况

  • 如果尚未得到有效结果,工具将求解网络分析图层。

参数

标注说明数据类型
输入网络分析图层

将生成方向信息的网络分析图层。 仅可针对路线、最近设施点和车辆配送 (VRP) 网络分析图层生成方向。

警告:
尽管这些图层类型支持方向,但此工具不支持最后一公里配送或废弃物收集分析图层。

Network Analyst Layer
输出文件类型

指定输出方向文件将使用的格式。 如果样式表参数有值,则忽略此参数。

  • XML将以 .xml 文件的形式生成输出方向文件。 除了方向字符串和路线的长度和时间信息之外,文件还将包含有关每个方向的行进策略类型和转弯角度的信息。
  • 文本输出方向文件将生成为简单 .txt 文件,其中包含路线的方向字符串、长度以及(可选)时间信息。
  • HTML输出方向文件将生成为包含路线的方向字符串、长度以及(可选)时间信息的 .html 文件。
String
输出方向文件

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

如果为 Stylesheet 参数提供样式表,请确保输出方向文件值的文件后缀与样式表生成的文件类型相匹配。

File
报告长度单位

指定将在方向文件中使用的线性单位。 例如,即使阻抗属性的单位是米,也可以用英里来显示方向。

  • 英尺线性单位为英尺。
  • 线性单位为码。
  • 英里线性单位为英里。
  • 线性单位为米。
  • 千米线性单位为公里。
  • 海里线性单位为海里。
String
报告行驶时间
(可选)

指定是否在方向文件中报告行驶时间。

  • 选中 - 将在方向文件中报告行驶时间。 这是默认设置。
  • 未选中 - 将不在方向文件中报告行驶时间。
Boolean
时间属性
(可选)

用于提供方向中各行驶时间的基于时间的成本属性。 成本属性必须存在于输入网络分析图层所使用的网络数据集上。 对于使用时间窗的车辆配送 (VRP) 图层和路线图层,仅出行模式的成本属性可用于此参数。

String
语言
(可选)

行驶方向所使用的语言。

使用两位或五位字符的语言代码来表示此参数值可用于生成方向的语言之一。 在 Python 中,可使用 ListDirectionsLanguages 函数检索可用语言代码列表。

String
样式名称
(可选)

指定用于方向的格式样式。

  • 可打印驾车方向将使用可打印转弯方向。
  • 导航设备的驾车方向将使用针对车辆内导航设备设计的转弯方向。
  • 行走方向将使用用于人行道的转弯行走方向。
String
样式表
(可选)

将用于生成格式化输出文件类型(如 PDF、Word 或 HTML)的样式表。 输出方向文件参数中的文件后缀必须与样式表所生成的文件类型相匹配。 如果此参数中包含了参数值,则工具会重写输出文件类型参数。

提示:

要创建自定义 HTML 和文本样式表,请从 Network Analyst 复制并编辑样式表。 样式表可在 <ArcGIS installation directory>\AllSource\Resources\NetworkAnalyst\Directions\Styles 目录中找到。 HTML 样式表是 Dir2PHTML.xsl,文本样式表是 Dir2PlainText.xsl

File

派生输出

标注说明数据类型
网络分析图层

已更新的带路径的网络分析图层。

Network Analyst Layer

arcpy.management.Directions(in_network_analysis_layer, file_type, out_directions_file, report_units, {report_time}, {time_attribute}, {language}, {style_name}, {stylesheet})
名称说明数据类型
in_network_analysis_layer

将生成方向信息的网络分析图层。 仅可针对路线、最近设施点和车辆配送 (VRP) 网络分析图层生成方向。

警告:
尽管这些图层类型支持方向,但此工具不支持最后一公里配送或废弃物收集分析图层。

Network Analyst Layer
file_type

指定输出方向文件将使用的格式。 如果样式表参数有值,则忽略此参数。

  • XML将以 .xml 文件的形式生成输出方向文件。 除了方向字符串和路线的长度和时间信息之外,文件还将包含有关每个方向的行进策略类型和转弯角度的信息。
  • TEXT输出方向文件将生成为简单 .txt 文件,其中包含路线的方向字符串、长度以及(可选)时间信息。
  • HTML输出方向文件将生成为包含路线的方向字符串、长度以及(可选)时间信息的 .html 文件。
String
out_directions_file

如果提供 stylesheet 参数的样式表,应确保 out_directions_file 值的文件后缀与样式表生成的文件类型匹配。

File
report_units

指定将在方向文件中使用的线性单位。 例如,即使阻抗属性的单位是米,也可以用英里来显示方向。

  • Feet线性单位为英尺。
  • Yards线性单位为码。
  • Miles线性单位为英里。
  • Meters线性单位为米。
  • Kilometers线性单位为公里。
  • NauticalMiles线性单位为海里。
String
report_time
(可选)

指定是否在方向文件中报告行驶时间。

  • NO_REPORT_TIME将不在方向文件中报告行驶时间。
  • REPORT_TIME将在方向文件中报告行驶时间。 这是默认设置。
Boolean
time_attribute
(可选)

用于提供方向中各行驶时间的基于时间的成本属性。 成本属性必须存在于输入网络分析图层所使用的网络数据集上。 对于使用时间窗的车辆配送 (VRP) 图层和路线图层,仅出行模式的成本属性可用于此参数。

String
language
(可选)

行驶方向所使用的语言。

使用两位或五位字符的语言代码来表示此参数值可用于生成方向的语言之一。 在 Python 中,可使用 ListDirectionsLanguages 函数检索可用语言代码列表。

String
style_name
(可选)

指定用于方向的格式样式。

  • NA Desktop将使用可打印转弯方向。
  • NA Navigation将使用针对车辆内导航设备设计的转弯方向。
  • NA Campus将使用用于人行道的转弯行走方向。
String
stylesheet
(可选)

将用于生成格式化输出文件类型(如 PDF、Word 或 HTML)的样式表。 输出方向文件参数中的文件后缀必须与样式表所生成的文件类型相匹配。 如果此参数中包含了参数值,则工具会重写输出文件类型参数。

提示:

要创建自定义 HTML 和文本样式表,请从 Network Analyst 复制并编辑样式表。 样式表可在 <ArcGIS installation directory>\AllSource\Resources\NetworkAnalyst\Directions\Styles 目录中找到。 HTML 样式表是 Dir2PHTML.xsl,文本样式表是 Dir2PlainText.xsl

File

派生输出

名称说明数据类型
output_layer

已更新的带路径的网络分析图层。

Network Analyst Layer

代码示例

Directions 示例 1(Python 窗口)

以下代码示例使用带所有参数的 Directions 函数进行演示:

arcpy.na.Directions("Route", "TEXT", "C:/Data/Route_Directions.txt", "Miles",
                    "REPORT_TIME", "Minutes")
Directions 示例 2(工作流)

以下独立 Python 脚本演示了使用 Directions 函数为某条路径生成一个 .html 文件格式的驾车方向。

# Name: Directions_Workflow.py
# Description: Generate driving directions in an html file for a route that
#              visits the store locations in the best sequence in order to
#              minimize the total travel time
# 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 inputs and outputs
    input_gdb = "C:/Data/SanFrancisco.gdb"
    network = os.path.join(input_gdb, "Transportation", "Streets_ND")
    layer_name = "StoreRoute"
    impedance = "TravelTime"
    start_location = os.path.join(input_gdb, "Analysis", "DistributionCenter")
    store_locations = os.path.join(input_gdb, "Analysis", "Stores")
    output_directions = os.path.join(output_dir,
                                                layer_name + "_Directions.html")
    output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")

    #Create a new route layer. The route starts at the distribution center and
    #visits the stores in the best order to yield the shortest travel time.
    result_object = arcpy.na.MakeRouteLayer(network, layer_name, impedance,
                                         "FIND_BEST_ORDER", "PRESERVE_FIRST",
                                         "", ['Meters'], "NO_UTURNS",
                                         start_date_time="8 AM")

    #Get the layer object from the result object. The route layer can
    #now be referenced using the layer object.
    layer_object = result_object.getOutput(0)

    #Get the names of all the sublayers within the route layer.
    sublayer_names = arcpy.na.GetNAClassNames(layer_object)
    #Stores the layer names that we will use later
    stops_layer_name = sublayer_names["Stops"]

    #Load the distribution center as the start location using default field
    #mappings and search tolerance
    arcpy.na.AddLocations(layer_object, stops_layer_name, start_location, "",
                            "", exclude_restricted_elements = "EXCLUDE")

    #Load the store locations as stops. Make sure the store locations are
    #appended to the Stops sublayer so the distribution center you just loaded
    #isn't overwritten. Map the ServiceTime field from the input data to the
    #Attr_TravelTime property in the Stops sublayer so that the time it takes to
    #service each store is included in the total travel time for the route.
    field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
                                                            stops_layer_name)
    field_mappings["Name"].mappedFieldName = "Name"
    field_mappings["Attr_" + impedance].mappedFieldName = "ServiceTime"
    arcpy.na.AddLocations(layer_object, stops_layer_name, store_locations,
                          field_mappings, "", append="APPEND",
                          exclude_restricted_elements = "EXCLUDE")

    #Generate driving directions in an HTML file
    arcpy.na.Directions(layer_object, "HTML", output_directions, "Miles",
                        "REPORT_TIME", impedance)

    #Save the solved na layer as a layer file on disk
    layer_object.saveACopy(output_layer_file)

    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 occurred on line %i" % tb.tb_lineno))
    print((str(e)))