Skip To Content

StreetDirectionsProperties

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

PropertyExplanationData Type
language
(Read and Write)

Specifies the language in which the output text directions are written. Available languages depend on the languages installed on your machine and can be checked 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:

  • Feet
  • Kilometers
  • Meters
  • Miles
  • NauticalMiles
  • Yards
String
styleName
(Read and Write)

Specifies 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 upon the styles installed on your machine and can be checked using the ListDirectionsStyleNames function.

String
timeAttribute
(Read and Write)

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

Indicates the spatial reference for the output directions feature class. Input to this attribute must be a spatial reference object.

SpatialReference

Code sample

StreetDirectionsProperties example (Workflow)

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

Related topics