复制遍历的源要素 (Network Analyst)

描述

创建两个要素类和一个表,它们组合在一起以包含求解网络分析图层时所遍历的边、交汇点和转弯的信息。

了解“复制遍历的源要素”的输出

使用方法

  • 该工具用于在输入网络分析图层未得到求解的情况下求解该图层。如果自上次求解后对输入进行了更改,则会重新求解分析图层。

  • 可以为以下网络分析图层生成遍历源要素:

    • 路径
    • 服务区
    • 最近设施点
    • 车辆配送 (VRP)

    无法为以下图层生成遍历源要素:

    • OD 成本矩阵
    • 位置分配

  • 输出交汇点要素类不仅包含代表遍历网络交汇点的点,而且还包含代表以下内容的点:

    • 遍历的点障碍
    • 遍历的线障碍和面障碍的进入点和退出点
    • 路径分析中的已访问停靠点
    • 服务区分析中的已访问设施点和中断端点
    • 最近设施点分析中的已访问设施点和事件点
    • 车辆配送中的已访问停靠点、站点和休息点

    了解“复制遍历的源要素”的输出

  • 可以通过指定“输出坐标系”环境设置或通过将地理数据库中的要素数据集指定为“输出位置”参数的值来控制输出要素类的坐标系。如果未指定“输出坐标系”环境设置或“输出位置”参数并非要素数据集,则输出要素类的坐标系与输入网络分析图层相同。

语法

arcpy.na.CopyTraversedSourceFeatures(input_network_analysis_layer, output_location, edge_feature_class_name, junction_feature_class_name, turn_table_name)
参数说明数据类型
input_network_analysis_layer

将复制遍历源要素的网络分析图层。如果网络分析图层没有有效结果,则会通过求解图层以生成有效结果。

Network Analyst Layer
output_location

用来保存输出表和两个要素类的工作空间。

Workspace; Feature Dataset
edge_feature_class_name

将包含遍历边源要素相关信息的要素类的名称。如果求解的网络分析图层不遍历任何边要素,则会创建空要素类。

String
junction_feature_class_name

将包含遍历交汇点源要素(包括输入网络分析图层中的系统交汇点和相关点)相关信息的要素类的名称。如果求解的网络分析图层不遍历任何交汇点,则会创建空要素类。

String
turn_table_name

将包含基础边成本按比例增加的遍历通用转弯和转弯要素相关信息的表的名称。如果求解的网络分析图层不遍历任何转弯,则会创建空表。因为始终不会遍历受限制的转弯,因此它们始终不会包含在输出中。

String

派生输出

名称说明数据类型
edge_features

包含在网络分析中遍历的网络数据集边的要素类。

要素类
junction_features

包含在网络分析中遍历的网络数据集交汇点的要素类。

要素类
turn_table

包含在网络分析中遍历的网络数据集转弯的表。

Table
modified_input_network_analysis_layer

已求解的网络分析图层。

网络分析图层

代码示例

CopyTraversedSourceFeatures 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何使用 CopyTraversedSourceFeatures 工具在内存工作空间中将遍历的边、交汇点和转弯从“路径”网络分析图层写入到要素类和表中。

arcpy.na.CopyTraversedSourceFeatures("Route", "C:/Data/Output.gdb",
                                     "TraversedEdges",
                                     "TraversedJunctions",
                                     "TraversedTurns")
CopyTraversedSourceFeatures 示例 2(工作流)

以下独立 Python 脚本演示了如何使用 CopyTraversedSourceFeatures 来查找从人口普查区域质心到最近消防站的路径的共有街道。这些结果有助于确定在紧急情况下使用最为频繁的街道。

# Name: CopyTraversedSourceFeatures_ex02.py
# Description: The scenario shows how to find the streets that are common to the
#              routes between the closest fire station and the census tract
#              centroids. These streets can be used to identify critical points
#              in case of an emergency.
# Requirements: Network Analyst Extension

#Import system modules
import os
import arcpy
from arcpy import env

try:
    #Check out Network Analyst license if available. Fail if the Network Analyst license is not available.
    if arcpy.CheckExtension("network") == "Available":
        arcpy.CheckOutExtension("network")
    else:
        raise arcpy.ExecuteError("Network Analyst Extension license is not available.")
    
    #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
    env.qualifiedFieldNames = False

    #Set local variables
    input_gdb = "C:/Data/SanFrancisco.gdb"
    output_gdb = "C:/Data/Output.gdb"
    network = os.path.join(input_gdb, "Transportation", "Streets_ND")
    layer_name = "EmergencyRoutes"
    travel_mode = "Driving Time"
    facilities = os.path.join(input_gdb, "Analysis", "FireStations")
    incidents = os.path.join(input_gdb, "Analysis", "TractCentroids")
    edge_frequency = os.path.join(output_gdb, "EdgeFrequency")
    critical_streets = os.path.join(output_gdb, "CriticalStreets")

    #Create a new closest facility analysis layer.
    result_object = arcpy.na.MakeClosestFacilityAnalysisLayer(network,
                                                layer_name, travel_mode,
                                                "FROM_FACILITIES")

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

    #Get the names of all the sublayers within the closest facility layer.
    sublayer_names = arcpy.na.GetNAClassNames(layer_object)
    #Stores the layer names that we will use later
    facilities_layer_name = sublayer_names["Facilities"]
    incidents_layer_name = sublayer_names["Incidents"]

    #Load fire station features as facilities and ensure that they are not
    #located on restricted portions of the network. Use default field mappings
    #and search tolerance
    arcpy.na.AddLocations(layer_object, facilities_layer_name, facilities, "",
                          "", exclude_restricted_elements="EXCLUDE")

    #Load tract centroids as incidents and ensure that they are not located on
    #restricted portions of the network. Map the ID field from Tract Centroids
    #as the name for incidents using field mappings
    field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
                                                        incidents_layer_name)
    field_mappings['Name'].mappedFieldName = "ID"
    arcpy.na.AddLocations(layer_object, incidents_layer_name, incidents,
                          field_mappings, "",
                          exclude_restricted_elements="EXCLUDE")

    #Solve the closest facility layer and copy the travered source features to
    #the output geodatabase. Use default names for the output feature
    #classes and table. Retrieve the first output, which is the traversed edges.
    traversed_edges = arcpy.na.CopyTraversedSourceFeatures(layer_object,
                                                      output_gdb).getOutput(0)

    #Some streets might be traversed by more than one route. Streets traversed
    #by many routes are the most critical emergency routes. Count the number of
    #routes using each street.
    arcpy.analysis.Frequency(traversed_edges, edge_frequency,
                             ["SourceOID", "SourceName"])

    #The resulting edge features from CopyTraversedSourceFeatures may include
    #clipped versions of the original street features because the Closest
    #Facility route only traveled across part of the street feature. Select
    #the complete street features from the original street feature class and
    #copy them to output.
    #Get the full path to the network dataset's streets feature class by
    #describing the network dataset.
    network_desc = arcpy.Describe(network)
    edge_sources = network_desc.edgeSources
    for es in edge_sources:
        if es.name.lower() == "streets":
            streets_source = os.path.join(os.path.dirname(network), es.name)
            break

    #Select the relevant streets based on overlap with the results from
    #CopyTraversedSourceFeatures
    streets_layer = arcpy.management.MakeFeatureLayer(streets_source,
                                                        "StreetsLayer")
    arcpy.management.SelectLayerByLocation(streets_layer,
                                "SHARE_A_LINE_SEGMENT_WITH", traversed_edges)

    #Add the frequency information to the output feature class using JoinField
    arcpy.management.JoinField(streets_layer, "ObjectID", edge_frequency,
                               "SourceOID", "FREQUENCY")

    #Save the selected features to disk
    arcpy.management.CopyFeatures(streets_layer, critical_streets)

    #Delete the Frequency field from the street feature class
    arcpy.management.DeleteField(streets_layer, "FREQUENCY")

    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))

许可信息

  • Basic: 需要 Network Analyst
  • Standard: 需要 Network Analyst
  • Advanced: 需要 Network Analyst

相关主题