描述
提供了 NAClassFieldMap 对象字典,可用于映射网络分析图层内网络分析类的属性字段名称,或设置该属性的默认值。 字典关键字是网络分析类属性名称,值为 NAClassFieldMap 对象。
讨论
将 NAClassFieldMappings 对象或其字符串表示用作添加位置工具中 field_mappings 参数的输入。 NAClassFieldMappings 对象中所包含的 NAClassFieldMap 对象提供获取或设置网络分析类各属性的默认值以及对与属性关联的映射字段名称的访问权。
语法
NAClassFieldMappings (network_analyst_layer, sub_layer_name, {use_location_fields}, {list_candidate_fields})
参数 | 说明 | 数据类型 |
network_analyst_layer | 该变量引用一个从网络分析图层获取的 Layer 对象。该对象可以源自地图文档中的现有图层或向网络分析图层文件指定目录路径作为 Layer 类的参数。可以使用 Layer 对象上的 isNetworkAnalystLayer 属性来确认某个给定的 Layer 对象是否为网络分析图层。 | Layer |
sub_layer_name | 将要创建字段映射的子图层名称。名称必须针对特定网络分析图层类型有效。对于给定的网络分析图层,可使用 GetNAClassNames 功能确定子图层名称。 | String |
use_location_fields | 指定是否为网络位置属性与其他属性一起创建字段映射。 (默认值为 False) | Boolean |
list_candidate_fields [list_candidate_fields,...] | 用于生成映射字段名称的 Field 对象列表。可以使用 ListFields 功能从给定的要素类或表中获取参数值。如果未指定参数,则仅使用适当属性的默认值创建字段映射。 (默认值为 None) | Field |
代码示例
以下脚本显示如何将消防站作为设施点载入到现有服务区图层中,并使用 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 对象,以及如何使用添加位置工具将位置存储为停靠点。
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")