StreetDirectionsProperties (arcpy.na)

摘要

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

讨论

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

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

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

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

属性

属性说明数据类型
language
(读写)

指定写入输出文本方向时所采用的语言。具体的可用语言取决于您机器上安装的语言,可使用 ListDirectionsLanguages 函数进行查看。

String
lengthUnits
(读写)

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

  • Fee
  • Kilometers
  • Meters
  • Miles
  • NauticalMiles
  • Yards
String
styleName
(读写)

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

String
timeAttribute
(读写)

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

String
outputSpatialReference
(读写)

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

SpatialReference

代码实例

StreetDirectionsProperties 示例(工作流)

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

import arcpy

try:

    arcpy.CheckOutExtension("network")

    #Get the route layer object from a layer named "Route" in
    #the table of contents.
    RouteLayer = arcpy.mapping.Layer(r'C:\Data\Route.lyr')

    # Get the solver properties of the layer.
    SolverProps = arcpy.na.GetSolverProperties(RouteLayer)

    # Get the street directions properties
    DirectionsProps = SolverProps.streetDirectionsProperties

    # Set the lengthUnits to Kilometers
    DirectionsProps.lengthUnits = "Kilometers"

    # Set the outputSpatialReference to web mercator
    sr = arcpy.SpatialReference(3785)
    DirectionsProps.outputSpatialReference = sr

    # Get the time attribute used for directions for use later
    timeAttribute = DirectionsProps.timeAttribute

    #Generate directions features and save them to disk.
    arcpy.na.GenerateDirectionsFeatures(RouteLayer,
                                        r'C:\Data\Directions.gdb\RouteDirections')

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)

相关主题

5/10/2014