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.
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 solve.
Traversed source features can be generated for the following network analysis layers:
- Service area
- Closest facility
- Vehicle routing problem
Traversed source features cannot be generated for the following layers:
- OD cost matrix
The output junctions feature class not only includes points that represent traversed network junctions, it 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
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 is not a feature dataset, the output feature classes have the same coordinate system as the input network analysis layer.
arcpy.na.CopyTraversedSourceFeatures(input_network_analysis_layer, output_location, edge_feature_class_name, junction_feature_class_name, turn_table_name)
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|
The workspace where the output table and two feature classes will be saved.
|Workspace; Feature Dataset|
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 is created.
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 is created.
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 is created. Since restricted turns are never traversed, they are never included in the output.
A feature class containing the network dataset edges that were traversed in the network analysis.
A feature class containing the network dataset junctions that were traversed in the network analysis.
A table containing the network dataset turns that were traversed in the network analysis.
The solved network analysis layer.
|Network Analyst Layer|
CopyTraversedSourceFeatures example 1 (Python window)
The following Python window script demonstrates how to use the CopyTraversedSourceFeatures tool to write the traversed edges, junctions, and turns from a Route network analysis layer to feature classes and 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 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 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" outNALayerName = "EmergencyRoutes" impedanceAttribute = "TravelTime" inFacilities = "Analysis/FireStations" inIncidents = "Analysis/TractCentroids" edgeFrequency = "in_memory/EdgeFrequency" outLayerFile = "C:/data/output" + "/" + outNALayerName + ".lyr" outFeatures = "CriticalStreets" #Create a new closest facility analysis layer. For this scenario, the default #value for all the remaining parameters statisfies the analysis requirements outNALayer = arcpy.na.MakeClosestFacilityLayer(inNetworkDataset, outNALayerName, impedanceAttribute, "TRAVEL_FROM") #Get the layer object from the result object. The closest facility layer can #now be referenced using the layer object. outNALayer = outNALayer.getOutput(0) #Get the names of all the sublayers within the closest facility layer. subLayerNames = arcpy.na.GetNAClassNames(outNALayer) #Stores the layer names that we will use later facilitiesLayerName = subLayerNames["Facilities"] incidentsLayerName = subLayerNames["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(outNALayer,facilitiesLayerName,inFacilities,"", "", 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 fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, incidentsLayerName) fieldMappings['Name'].mappedFieldName = "ID" arcpy.na.AddLocations(outNALayer,incidentsLayerName, inIncidents, fieldMappings,"", exclude_restricted_elements = "EXCLUDE") #Solve the closest facility layer and copy the travered source features to a #temporary in-memory workspace. Use default names for the output feature #classes and table. Get only the first output which are the edges traversed. traversedEdges = arcpy.na.CopyTraversedSourceFeatures(outNALayer, "in_memory").getOutput(0) #Calculate the frequency of SourceOID in the traversed edges arcpy.analysis.Frequency(traversedEdges, edgeFrequency, ["SourceOID", "SourceName"]) #Get the full path to the streets feature class by describing the network #dataset referenced by the network analysis layer. network = arcpy.Describe(outNALayer.dataSource) edgeSources = network.edgeSources for es in edgeSources: if es.name.lower() == "streets": streetsSource = os.path.join(os.path.dirname(network.catalogPath), es.name) break else: raise Exception("Failed to detrmine the path for the streets feature class") #Join the frequency field to the streets feature class. In order to speed up #the join select the streets that share a line segment with traversed streets. streetsLayer = "StreetsLayer" arcpy.management.MakeFeatureLayer(streetsSource,streetsLayer) arcpy.management.SelectLayerByLocation(streetsLayer, "SHARE_A_LINE_SEGMENT_WITH", traversedEdges) arcpy.management.JoinField(streetsLayer, "ObjectID", edgeFrequency, "SourceOID", "FREQUENCY") #Copy the streets that have a frequency value to a new feature class. arcpy.management.SelectLayerByAttribute(streetsLayer, "SUBSET_SELECTION", "FREQUENCY IS NOT NULL") arcpy.management.CopyFeatures(streetsLayer,outFeatures) #Delete the Frequency field from the streets feature class arcpy.management.DeleteField(streetsLayer, "FREQUENCY") #Save the solved na layer as a layer file on disk with relative paths arcpy.management.SaveToLayerFile(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() print "An error occurred on line %i" % tb.tb_lineno print str(e)
- Basic: Requires Network Analyst
- Standard: Requires Network Analyst
- Advanced: Requires Network Analyst