ArcGIS Desktop

  • 文档
  • 支持

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

NAClassFieldMappings

  • 摘要
  • 说明
  • 语法
  • 代码示例

摘要

提供 NAClassFieldMap 对象的 Python 字典,用于映射网络分析图层内网络分析类的属性字段名称,或设置该属性的默认值。字典关键字是网络分析类属性名称,值为 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 示例 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")

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • 内部人员博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
© Copyright 2016 Environmental Systems Research Institute, Inc. | 隐私政策 | 法律声明