更新分析图层属性参数 (Network Analyst)

许可等级:BasicStandardAdvanced

摘要

更新网络分析图层的网络属性参数值。在使用求解工具求解前,应使用该工具更新网络分析图层的属性参数值。此操作将确保求解操作使用属性参数的特定值生成恰当的结果。

用法

语法

UpdateAnalysisLayerAttributeParameter_na (in_network_analysis_layer, parameterized_attribute, attribute_parameter_name, {attribute_parameter_value})
参数说明数据类型
in_network_analysis_layer

要更新属性参数值的网络分析图层。

Network Analyst Layer
parameterized_attribute

要更新属性参数的网络属性。

String
attribute_parameter_name

要更新的网络属性的参数。“对象”类型的参数不能使用该工具进行更新。

String
attribute_parameter_value
(可选)

要为属性参数设置的值。该值可以是字符串、数值、日期或布尔值(True 和 False)。如果未指定值,则属性参数值将被设置为空。

如果属性参数为限制使用类型,则参数值可被指定为字符串关键字或数值。字符串关键字或数值决定了限制属性是否禁止、避开或优先选择与之关联的网络元素。并且,网络元素避开或优先选择的程度可通过选择 HIGH、MEDIUM、或 LOW 关键字来定义。可支持的关键字如下:

  • PROHIBITED
  • AVOID_HIGH
  • AVOID_MEDIUM
  • AVOID_LOW
  • PREFER_LOW
  • PREFER_MEDIUM
  • PREFER_HIGH

大于一的数值会避开限制元素;数值越大,避开的元素就越多。零和一之间的数值会导致优先选择限制元素;数值越小,优先选择的限制元素就越多。负值会禁止限制元素。

提示提示:

如果参数值包含一个数组,则使用本地分隔符分隔数组中的各项。例如,在美国,最有可能使用逗号分隔项目。因此表示包含三个数值的数组可以显示为: "5,10,15".

String

代码实例

更新分析图层属性参数 (UpdateAnalysisLayerAttributeParameter) 示例 1(Python 窗口)

使用所有参数执行工具。

import arcpy
arcpy.na.UpdateAnalysisLayerAttributeParameter("Route", "Height Restriction",
                                               "Vehicle Height (feet)", 12.0)
更新分析图层属性参数 (UpdateAnalysisLayerAttributeParameter) 示例 2(工作流)

以下独立 Python 脚本演示了如何使用“更新分析图层属性参数”工具来查找卡车为了避开低间距天桥或隧道、避开收费公路并且优先选择指定的货车路径而采用的最佳路径。

# Name: UpdateAnalysisLayerAttributeParameter_Workflow.py
# Description: Find the best route for trucks that avoids low clearance 
#              overpasses or tunnels, avoids toll roads and prefers desginated
#              truck routes. The results are saved to a layer file.
# 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/SanDiego.gdb"
    env.overwriteOutput = True
    
    #Set local variables
    inNetworkDataset = "Transportation/Streets_ND"
    outNALayerName = "BestTruckRoute"
    impedanceAttribute = "TravelTime"
    accumulateAttribute = ['Meters']
    tollRoadRestriction = "Avoid Toll Roads"
    preferTruckRouteRestriction = "National STAA Preferred Route"
    parameterName = "Restriction Usage"
    inStops = "Analysis/Customers"
    outLayerFile = "C:/data/output" + "/" + outNALayerName + ".lyr"
    
    #Make a new route layer. Along with the total travel time, we also want to
    #find out the total distance. So we accumulate "Meters" attribute. We will
    #create the route layer with defaultrestrictions and add the additional 
    #restrictions that we want the routes to honor.
    outNALayer = arcpy.na.MakeRouteLayer(inNetworkDataset, outNALayerName,
                                         impedanceAttribute, "", "", "",
                                         accumulateAttribute,"NO_UTURNS")
    #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"]
    
    #Modify the restriction attributes for the route layer. We don't want to use
    #Driving an Automobile restriction and wan't to use Driving a Truck,
    #Avoid Toll Roads and National STAA Preferred Route restrictions.
    solverProperties = arcpy.na.GetSolverProperties(outNALayer)
    defaultRestrictions = solverProperties.restrictions
    defaultRestrictions.remove("Driving an Automobile")
    defaultRestrictions += ["Driving a Truck", tollRoadRestriction,
                            preferTruckRouteRestriction]
    solverProperties.restrictions = defaultRestrictions
    
    #Load the Delivery locations as stops using default field mappings
    arcpy.na.AddLocations(outNALayer, stopsLayerName, inStops, "", "")
    
    #As we wish avoid toll roads as much as possible and highly prefer the 
    #designated turck routes, we set the appropriate parameter values for the 
    #Restriction Usage parameter for these two restriction attributes.
    arcpy.na.UpdateAnalysisLayerAttributeParameter(outNALayer, tollRoadRestriction,
                                                   parameterName, "AVOID_HIGH")
    arcpy.na.UpdateAnalysisLayerAttributeParameter(outNALayer,
                                                   preferTruckRouteRestriction,
                                                   parameterName, "PREFER_HIGH")
    
    #Solve the route layer
    arcpy.na.Solve(outNALayer)
    
    #Save the solved route layer as a layer file on disk using relative paths
    arcpy.management.SaveToLayerFile(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 occured on line %i" % tb.tb_lineno
    print str(e)

环境

相关主题

许可信息

ArcGIS for Desktop Basic:是
ArcGIS for Desktop Standard:是
ArcGIS for Desktop Advanced:是
9/15/2013