Skip to main content

StreetDirectionsProperties

汇总

为街道方向属性提供读写访问,用于自定义网络分析图层的方向输出。 可通过 SolverProperties 对象(可通过 GetSolverProperties 函数获取)读取和设置 StreetDirectionsProperties 对象。

讨论

StreetDirectionsProperties 对象可为街道方向属性提供读写访问,用于自定义网络分析图层的方向输出。

可以读取和设置的属性包括 languagelengthUnitsstyleNametimeAttributeoutputSpatialReference

StreetDirectionsProperties 对象仅适用于路径、最近设施点和车辆配送网络分析图层。 此外,在不支持方向的网络数据集上构建的网络分析图层也不支持使用 StreetDirectionsProperties 对象。 如果该图层不受支持,则将返回一个 Python None 对象。

修改 StreetDirectionsProperties 对象的属性后,相应的图层可立即与其他函数和地理处理工具配合使用。 无需刷新或更新图层,通过上述对象进行的修改便可生效。

属性

名称 说明 数据类型

enabled

(读取和写入)

指定求解图层时是否生成方向。如果不需要方向,请将此参数设置为 False 以提高求解性能。

Boolean

language

(读取和写入)

写入输出文本方向时所采用的语言。此参数的输入应为 两位或五位字符语言代码,表示用于方向生成的可用语言之一 。可使用 ListDirectionsLanguages 函数检索可用语言代码列表。

String

lengthUnits

(读取和写入)

指定输出文本方向中用于测量长度的距离单位。这些单位必须是以下字符串值中的一个:

  • 英尺

  • 千米

  • 英里

  • 海里

String

styleName

(读取和写入)

输出文本方向的样式。对于打印、在导航设备上使用或查找步行路径等不同的应用,提供的样式也不同。具体的可用样式取决于您机器上安装的样式,可使用 ListDirectionsStyleNames 函数进行查看。

String

timeAttribute

(读取和写入)

基于时间的网络数据集成本属性可用于计算输出方向上的行驶时间。可用的 timeAttribute 值是网络数据集的一个属性。您可使用网络数据集 describe 对象来在网络数据集中列出各个 成本属性

String

outputSpatialReference

(读取和写入)

输出方向要素类的空间参考。此属性的输入必须是一个 SpatialReference 对象。

SpatialReference

代码示例

StreetDirectionsProperties 示例(工作流)

读取路径图层,将其长度单位设置为千米并生成方向要素。

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