Directions (Network Analyst)

Summary

Generates direction information from a network analysis layer with routes. The direction information is written to a file in either XML or text format.

Usage

Syntax

Directions_na (in_network_analysis_layer, file_type, out_directions_file, report_units, {report_time}, {time_attribute})
ParameterExplanationData Type
in_network_analysis_layer

Network analysis layer from which directions will be generated. Directions can be generated only for the Route, Closest Facility, and Vehicle Routing Problem network analysis layers.

Network Analyst Layer
file_type

The format of the output directions file.

  • XMLThe output directions file will be generated as an XML file. Apart from direction strings and the length and time information for the routes, the file will also contain information about the maneuver type and the turn angle for each direction. You should use XML format if you wish to apply your own formatting to display the directions.
  • TEXTThe output directions file will be generated as a simple TEXT file containing the direction strings, the length and, optionally, the time information for the routes.
String
out_directions_file

The full pathname to the directions file that will be written.

File
report_units

Specifies the linear units in which the length information will be reported in the directions file. For example, even though your impedance was in meters, you can show directions in miles.

String
report_time
(Optional)
  • NO_REPORT_TIMEDo not report travel times in the directions file.
  • REPORT_TIMEReport travel times in the directions file.
Boolean
time_attribute
(Optional)

The time-based cost attribute providing the travel times in the directions. The cost attribute must exist on the network dataset used by the input network analysis layer.

String

Code Sample

Directions example 1 (Python window)

Execute the Directions tool with all the parameters.

import arcpy
arcpy.Directions_na("Route","TEXT","C:/temp/Route_Directions.txt","Miles",
                    "REPORT_TIME","Minutes")
Directions example 2 (workflow)

The following stand-alone Python script demonstrates how the Directions tool can be used to generate driving directions in a text file for a route.

# 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 
# Author: ESRI

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

Environments

Related Topics

Licensing Information

ArcView: Requires Network Analyst
ArcEditor: Requires Network Analyst
ArcInfo: Requires Network Analyst

Published 6/7/2010