Summary
Provides read and write access to street directions properties, allowing you to customize the directions output from your network analysis layers. The StreetDirectionsProperties can be read from and set on a SolverProperties object obtained through the GetSolverProperties function.
Discussion
The StreetDirectionsProperties object provides read and write access to street directions properties, allowing you to customize the directions output from your network analysis layers.
Properties that can be read and set include language, lengthUnits, styleName, timeAttribute, outputSpatialReference.
The StreetDirectionsProperties object is only available on Route, Closest Facility, and Vehicle Routing Problem network analysis layers. The other network analysis layer types do not support output directions. Additionally, the StreetDirectionsProperties object will not be available on network analysis layers built on network datasets that don't support directions. A Python None object will be returned if the layer is not supported.
After modifying the properties of the StreetDirectionsProperties object, the corresponding layer can be immediately used with other functions and geoprocessing tools. There is no refresh or update of the layer required to honor the changes modified through the object.
Properties
Property | Explanation | Data Type |
enabled (Read and Write) | Specifies whether directions will be generated when solving the layer. If directions are not needed, set this parameter to False to improve solve performance. | Boolean |
language (Read and Write) | The language in which the output text directions are written. The input for this parameter should be a two- or five-character language code representing one of the available languages for directions generation. You can retrieve a list of available language codes using the ListDirectionsLanguages function. | String |
lengthUnits (Read and Write) | Specifies the distance units used to measure lengths in the output text directions. The units must be one of the following string values:
| String |
styleName (Read and Write) | The style of the output text directions. Different styles are available for different applications, such as printing, using on a navigation device, or routing a pedestrian. Available styles depend on the styles installed on your machine and can be checked using the ListDirectionsStyleNames function. | String |
timeAttribute (Read and Write) | The time-based network dataset cost attribute that is used to calculate the travel time in the output directions. The available timeAttribute values are a property of the network dataset. You can list the cost attributes in your network dataset using a network dataset describe object. | String |
outputSpatialReference (Read and Write) | The spatial reference for the output directions feature class. Input to this attribute must be a SpatialReference object. | SpatialReference |
Code sample
Reads a route layer, sets its length units to kilometers, and generates directions features.
# Name: StreetDirectionsProperties.py
# Description: Read a route layer from a layer file on disk, change the
# directions properties, and generate directions features
# Requirements: Network Analyst Extension
#Import system modules
import arcpy
try:
#Get the route layer object from a layer file on disk
layer_object = arcpy.mp.LayerFile(r'C:\Data\Route.lyrx').listLayers()[0]
#Get the solver properties of the layer.
solver_props = arcpy.na.GetSolverProperties(layer_object)
#Get the street directions properties
directions_props = solver_props.streetDirectionsProperties
#Set the lengthUnits to Kilometers
directions_props.lengthUnits = "Kilometers"
#Set the outputSpatialReference to web mercator
sr = arcpy.SpatialReference(3785)
directions_props.outputSpatialReference = sr
#Generate directions features and save them to disk.
arcpy.na.GenerateDirectionsFeatures(layer_object,
r'C:\Data\Output.gdb\RouteDirections')
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))