ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Directions

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

Generates turn-by-turn directions from a network analysis layer with routes. The directions can be written to a file in text, XML, or HTML format. If you provide an appropriate stylesheet, the directions can be written to any other file format.

Usage

  • The tool solves the network analysis layer if it does not already have a valid result, so it is not required to solve the network analysis layer before generating directions.

Syntax

arcpy.na.Directions(in_network_analysis_layer, file_type, out_directions_file, report_units, {report_time}, {time_attribute}, {language}, {style_name}, {stylesheet})
ParameterExplanationData Type
in_network_analysis_layer

Network analysis layer for which directions will be generated. Directions can be generated only for route, closest facility, and vehicle routing problem network analysis layers.

Network Analyst Layer
file_type

The format of the output directions file. This parameter is ignored if the stylesheet parameter has a value.

  • XML —The 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.
  • TEXT —The output directions file will be generated as a simple TXT file containing the direction strings, the length and, optionally, the time information for the routes.
  • HTML —The output directions file will be generated as an HTML file containing the direction strings, the length and, optionally, the time information for the routes.
String
out_directions_file

If you provide a stylesheet in the stylesheet parameter, make sure the file suffix for out_directions_file matches the file type your stylesheet produces.

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.

  • Feet —Feet
  • Yards —Yards
  • Miles —Miles
  • Meters —Meters
  • Kilometers —Kilometers
  • NauticalMiles —Nautical miles
String
report_time
(Optional)
  • NO_REPORT_TIME —Do not report travel times in the directions file.
  • REPORT_TIME —Report travel times in the directions file. This is the default.
Boolean
time_attribute
(Optional)

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

String
language
(Optional)

Choose a language in which to generate driving directions. The languages that are shown in the drop-down list depend on which ArcGIS language packs are installed on your computer.

Note that if you are going to publish this tool as part of a service on a separate server, the ArcGIS language pack that corresponds with the language you choose must be installed on that server for the tool to function properly. Also, if a language pack isn't installed on your computer, the language won't appear in the drop-down list; however, you can type a language code instead of choosing one.

String
style_name
(Optional)

Choose the name of the formatting style for the directions.

  • NA Desktop —Printable turn-by-turn directions
  • NA Navigation —Turn-by-turn directions designed for an in-vehicle navigation device
  • NA Campus —Turn-by-turn walking directions, which are designed for pedestrian routes
String
stylesheet
(Optional)

The stylesheet for generating a formatted output file type (such as a PDF, Word, or HTML file). The suffix of the file in the output directions file parameter should match the file type that the stylesheet generates. The Directions tool overrides the output file type parameter if this parameter contains a value.

Tip:

If you want a head start on creating your own text and HTML stylesheets, copy and edit the stylesheets Network Analyst uses. You can find them in the following directory: <ArcGIS installation directory>\ArcGIS\Desktop10.2.1\NetworkAnalyst\Directions\Styles. The stylesheet is Dir2PHTML.xsl, and the text stylesheet is Dir2PlainText.xsl.

File

Derived Output

NameExplanationData Type
output_layer

The updated network analysis layer with routes.

Network Analyst Layer

Code sample

Directions example 1 (Python window)

Execute the Directions tool with all the parameters.

arcpy.na.Directions("Route", "TEXT", "C:/Data/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 HTML file for a route.

# Name: Directions_Workflow.py
# Description: Generate driving directions in a html file for a route that 
#              visits the store locations in the best sequence that minimizes 
#              the total travel time
# Requirements: Network Analyst Extension 

#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"
    outNALayerName = "StoreRoute"
    impedanceAttribute = "TravelTime"
    startLocation = "Analysis/DistributionCenter"
    storeLocations = "Analysis/Stores"
    #fieldMappings = "Name Name #; Attr_TravelTime ServiceTime #"
    outDirectionsFile = "C:/data/output" + "/" + outNALayerName + "Directions.html"
    outLayerFile = "C:/data/output" + "/" + outNALayerName + ".lyr"
    
    #Create a new route layer. The route starts at the distribution center and 
    #takes the best sequence to visit the store locations.
    outNALayer = arcpy.na.MakeRouteLayer(inNetworkDataset, outNALayerName,
                                         impedanceAttribute, "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.
    outNALayer = outNALayer.getOutput(0)
    
    #Get the names of all the sublayers within the route layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Stores the layer names that we will use later
    stopsLayerName = subLayerNames["Stops"]
    
    #Load the distribution center as the start location using default field 
    #mappings and search tolerance
    arcpy.na.AddLocations(outNALayer,stopsLayerName,startLocation,"","",
                          exclude_restricted_elements = "EXCLUDE")
    
    #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 using the field mappings
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, stopsLayerName)
    fieldMappings["Name"].mappedFieldName = "Name"
    fieldMappings["Attr_" + impedanceAttribute].mappedFieldName = "ServiceTime"
    arcpy.na.AddLocations(outNALayer, stopsLayerName, storeLocations,
                          fieldMappings, "", append="APPEND",
                          exclude_restricted_elements = "EXCLUDE")
    
    #Generate driving directions in a HTML file
    arcpy.na.Directions(outNALayer,"HTML",outDirectionsFile,"Miles",
                        "REPORT_TIME",impedanceAttribute)
    
    #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 occurred on line %i" % tb.tb_lineno
    print str(e)

Environments

  • Current Workspace

Licensing information

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

Related topics

  • An overview of the Analysis toolset

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal