NAClassFieldMappings (arcpy.na)

摘要

提供 NAClassFieldMap 对象的 Python 字典,用于映射网络分析图层内网络分析类的属性字段名称,或设置该属性的默认值。字典关键字是网络分析类属性名称,值为 NAClassFieldMap 对象。

讨论

添加位置地理处理工具中,NAClassFieldMappings 对象或其字符串用作 field_mappings 参数的输入。NAClassFieldMappings 对象中所包含的 NAClassFieldMap 对象提供获取或设置网络分析类各属性的默认值以及对与属性关联的映射字段名称的访问权。

语法

NAClassFieldMappings (network_analyst_layer, sub_layer_name, {use_location_fields}, {list_candidate_fields})
参数说明数据类型
network_analyst_layer

A variable that references a Layer object obtained from a network analyst layer. It can be derived from existing layers in a map document or by specifying the catalog path to the network analyst layer file as an argument to the Layer class. The isNetworkAnalystLayer property on the layer object can be used to identify if a given layer object is a network analyst layer.

Layer
sub_layer_name

The sublayer name for which the field mappings are to be created. The name must be valid for the particular network analysis layer type. For a given network analysis layer, the sublayer name can be determined using the GetNAClassNames function.

String
use_location_fields

Specifies whether to create the field mappings for the network location properties along with other properties.

(默认值为 False)

Boolean
list_candidate_fields
[list_candidate_fields,...]

A list of Field objects that are used to generate the mapped field names. The argument value can be obtained from a given feature class or table using the ListFields function. If the argument is not specified, then the field mappings are created with only the default values for the appropriate properties.

(默认值为 None)

Field

代码实例

NAClassFieldMappings 示例 1(Python 窗口)

以下脚本显示如何将消防站作为设施点载入到现有服务区图层中,并使用 NAClassFieldMappings 对象在加载设施点时指定 10 分钟的延迟。它假设已对现有地图文档添加了基于旧金山地区网络数据集创建的名为 Fire Stations Coverage 的服务区网络分析图层,并添加了名为 FireStations 的要素图层。

#Get the service area layer called "Fire Stations Coverage" from the table of contents
saLayer = arcpy.mapping.Layer("Fire Stations Coverage")

#Get the list of fields from the FireStations feature layer in the table of contents
fields = arcpy.ListFields("FireStations")

#Get the facilities sublayer name from the service area layer. Note that we are not
#using a string called "Facilities" because the sublayer name can be
#different if using ArcGIS on a non-english operating system.
facilitiesSubLayerName = arcpy.na.GetNAClassNames(saLayer)["Facilities"]

#Create a field mappings object for facilities sublayer based on the fields from
#FireStations layer
fieldMappings = arcpy.na.NAClassFieldMappings(saLayer, facilitiesSubLayerName,
                                              False, fields)

#Get the field map corresponding to the "Attr_TravelTime" property of facilities
fieldMap = fieldMappings["Attr_TravelTime"]

#Set a delay of 10 minutes for the facilities
fieldMap.defaultValue = 10

#Load the fire stations as service area facilities using the field mappings
arcpy.na.AddLocations(saLayer, facilitiesSubLayerName, "FireStations", fieldMappings)
NAClassFieldMappings 示例 2(工作流)

该示例演示了在将天气条件作为减速障碍的情况下,如何寻找商店间的最佳路径。它说明如何在 NAClassFieldMappings 对象中使用“添加位置”工具加载天气图层作为面障碍,和商店位置作为停靠点。

import arcpy

#Set up the environment
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("network")

#Set up variables
networkDataset = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
polygonBarriers = "C:/Data/WeatherSlowDownAreas.shp"
stops = "C:/Data/SanFrancisco.gdb/Analysis/Stores"
impedanceAttribute = "TravelTime"
outputLayer = "C:/Data/WeatherRoute.lyr"

#Create a new route layer
routeLayer = arcpy.na.MakeRouteLayer(networkDataset, "WeatherRoute",
                                     impedanceAttribute).getOutput(0)
#Get na class names based on the layer
naClasses = arcpy.na.GetNAClassNames(routeLayer, "INPUT")
#Create field mappings for loading barriers as scaled cost polygon barriers
#with a slow down of 40%
fieldMappings = arcpy.na.NAClassFieldMappings(routeLayer,
                                              naClasses["PolygonBarriers"])
fieldMappings["BarrierType"].defaultValue = 1
fieldMappings["Attr_" + impedanceAttribute].defaultValue = 1.4
#Load weather polygons as slow down barriers
arcpy.na.AddLocations(routeLayer, naClasses["PolygonBarriers"],
                          polygonBarriers, fieldMappings)

#get a list of field objects from the stores feature class
storeFields = arcpy.ListFields(stops)
#Create field mappings for loading stops based on the field names from the stores
stopsFieldMappings = arcpy.na.NAClassFieldMappings(routeLayer, naClasses["PolygonBarriers"],
                                                   False, storeFields)
#Load stops using the field mappings
arcpy.na.AddLocations(routeLayer, naClasses["Stops"], stops, stopsFieldMappings)
#Solve the route
arcpy.na.Solve(routeLayer)
#Save the solved layer as a layer file
arcpy.management.SaveToLayerFile(routeLayer, outputLayer)
arcpy.AddMessage("Completed")
5/10/2014