更新分析图层属性参数 (Network Analyst)
摘要
更新网络分析图层的网络属性参数值。在使用求解工具求解前,应使用该工具更新网络分析图层的属性参数值。此操作将确保求解操作使用属性参数的特定值生成恰当的结果。
用法
-
参数化的网络属性用于对属性值的某个动态方面进行建模。例如,可使用某个参数对高度限制为 12 英尺的隧道进行建模。在这种情况下,应将以英尺为单位的车辆高度指定为参数值。这样,如果车辆高度大于 12 英尺,则此限制的计算结果将为真。类似的,桥梁还可以具有一个用来指定重量限制的参数。
-
此工具仅适用于定义了参数化的网络属性的网络分析图层。
-
求解网络分析图层前,可使用该工具重复更改现有参数的值。
-
新属性参数可通过目录 窗口或 ArcCatalog 中的网络数据集属性对话框创建。
语法
参数 | 说明 | 数据类型 |
in_network_analysis_layer |
要更新属性参数值的网络分析图层。 | Network Analyst Layer |
parameterized_attribute |
要更新属性参数的网络属性。 | String |
attribute_parameter_name |
要更新的网络属性的参数。“对象”类型的参数不能使用该工具进行更新。 | String |
attribute_parameter_value (可选) |
要为属性参数设置的值。该值可以是字符串、数值、日期或布尔值(True 和 False)。如果未指定值,则属性参数值将被设置为空。 如果属性参数为限制使用类型,则参数值可被指定为字符串关键字或数值。字符串关键字或数值决定了限制属性是否禁止、避开或优先选择与之关联的网络元素。并且,网络元素避开或优先选择的程度可通过选择 HIGH、MEDIUM、或 LOW 关键字来定义。可支持的关键字如下:
大于一的数值会避开限制元素;数值越大,避开的元素就越多。零和一之间的数值会导致优先选择限制元素;数值越小,优先选择的限制元素就越多。负值会禁止限制元素。 提示: 如果参数值包含一个数组,则使用本地分隔符分隔数组中的各项。例如,在美国,最有可能使用逗号分隔项目。因此表示包含三个数值的数组可以显示为: "5,10,15". | String |
代码实例
使用所有参数执行工具。
import arcpy
arcpy.na.UpdateAnalysisLayerAttributeParameter("Route", "Height Restriction",
"Vehicle Height (feet)", 12.0)
以下独立 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)