Copy Traversed Source Features (Network Analyst)

Summary

Creates two feature classes and a table, which together contain information about the edges, junctions, and turns that are traversed while solving a network analysis layer.

Learn about the output from Copy Traversed Source Features

Usage

  • The tool solves the input network analysis layer if it isn't already solved. The analysis layer is re-solved if any changes have been made to the inputs since the last time it was solved.

  • Traversed source features can be generated for the following network analysis layers:

    • Route
    • Service area
    • Closest facility
    • Vehicle routing problem
    • Last mile delivery

    Traversed source features cannot be generated for the following layers:

    • OD cost matrix
    • Location-allocation

  • In addition to points that represent traversed network junctions, the output junctions feature class also includes points that represent the following:

    • Traversed point barriers
    • Entry and exit points of traversed line and polygon barriers
    • Visited stops in a Route analysis
    • Visited facilities and the ends of breaks in a Service Area analysis
    • Visited facilities and incidents in a Closest Facility analysis
    • Visited orders, depots, and breaks in a Vehicle Routing Problem analysis
    • Visited orders and depots in a Last Mile Delivery analysis

  • The coordinate system for the output feature classes can be controlled by specifying the Output Coordinate System environment setting or by specifying a feature dataset in a geodatabase as the value for the Output Location parameter. If the Output Coordinate System environment setting is not specified or the Output Location parameter value is not a feature dataset, the output feature classes will have the same coordinate system as the input network analysis layer.

  • The tool will fail for Last Mile Delivery analysis layers that don't output directions and don't use route shapes because the traversal result is not generated.

Parameters

LabelExplanationData Type
Input Network Analysis Layer

The network analysis layer from which traversed source features will be copied. If the network analysis layer does not have a valid result, the layer will be solved to produce one.

Network Analyst Layer
Output Location

The workspace where the output table and two feature classes will be saved.

Workspace; Feature Dataset
Edge Feature Class Name

The name of the feature class that will contain information about the traversed edge source features. If the solved network analysis layer doesn't traverse any edge features, an empty feature class will be created.

String
Junction Feature Class Name

The name of the feature class that will contain information about the traversed junction source features, including system junctions and relevant points from the input network analysis layer. If the solved network analysis layer doesn't traverse any junctions, an empty feature class will be created.

String
Turn Table Name

The name of the table that will contain information about the traversed global turns and turn features that scale cost for the underlying edges. If the solved network analysis layer doesn't traverse any turns, an empty table will be created. Since restricted turns are never traversed, they are never included in the output.

String

Derived Output

LabelExplanationData Type
Edge Features

A feature class containing the network dataset edges that were traversed in the network analysis.

Feature Class
Junction Features

A feature class containing the network dataset junctions that were traversed in the network analysis.

Feature Class
Turn Table

A table containing the network dataset turns that were traversed in the network analysis.

Table
Modified Input Network Analysis Layer

The solved network analysis layer.

Network Analyst Layer

arcpy.na.CopyTraversedSourceFeatures(input_network_analysis_layer, output_location, edge_feature_class_name, junction_feature_class_name, turn_table_name)
NameExplanationData Type
input_network_analysis_layer

The network analysis layer from which traversed source features will be copied. If the network analysis layer does not have a valid result, the layer will be solved to produce one.

Network Analyst Layer
output_location

The workspace where the output table and two feature classes will be saved.

Workspace; Feature Dataset
edge_feature_class_name

The name of the feature class that will contain information about the traversed edge source features. If the solved network analysis layer doesn't traverse any edge features, an empty feature class will be created.

String
junction_feature_class_name

The name of the feature class that will contain information about the traversed junction source features, including system junctions and relevant points from the input network analysis layer. If the solved network analysis layer doesn't traverse any junctions, an empty feature class will be created.

String
turn_table_name

The name of the table that will contain information about the traversed global turns and turn features that scale cost for the underlying edges. If the solved network analysis layer doesn't traverse any turns, an empty table will be created. Since restricted turns are never traversed, they are never included in the output.

String

Derived Output

NameExplanationData Type
edge_features

A feature class containing the network dataset edges that were traversed in the network analysis.

Feature Class
junction_features

A feature class containing the network dataset junctions that were traversed in the network analysis.

Feature Class
turn_table

A table containing the network dataset turns that were traversed in the network analysis.

Table
modified_input_network_analysis_layer

The solved network analysis layer.

Network Analyst Layer

Code sample

CopyTraversedSourceFeatures example 1 (Python window)

The following Python window script demonstrates how to use the CopyTraversedSourceFeatures function to write the traversed edges, junctions, and turns from a Route network analysis layer to feature classes and a table in an in-memory workspace.

arcpy.na.CopyTraversedSourceFeatures("Route", "C:/Data/Output.gdb",
                                     "TraversedEdges",
                                     "TraversedJunctions",
                                     "TraversedTurns")
CopyTraversedSourceFeatures example 2 (workflow)

The following stand-alone Python script demonstrates how CopyTraversedSourceFeatures can be used to find the streets that are common to the routes from census tract centroids to the closest fire station. These results help identify which streets are most frequently used during emergencies.

# 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
    arcpy.na.AddLocations(layer_object, facilities_layer_name, facilities)

    # Load tract centroids as incidents. 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
    )

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

Licensing information

  • Basic: Requires Network Analyst
  • Standard: Requires Network Analyst
  • Advanced: Requires Network Analyst

Related topics