ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

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

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS Developers

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

ArcGIS Solutions

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

ArcGIS Marketplace

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

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

ArcMap

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

向分析图层添加字段

  • 描述
  • 使用方法
  • 语法
  • 代码示例
  • 环境
  • 许可信息

描述

向网络分析图层的子图层添加字段

使用方法

  • 该工具通常与添加位置工具配合使用,从而将输入要素中的字段传递到子图层。例如,如果想要将输入要素中名为 UniqueID 的字段传递到“服务区”图层的“设施点”子图层,请使用该工具先将 UniqueID 字段添加到“设施点”子图层,然后使用添加位置工具中的字段映射为 UniqueID 字段提供输入值。

  • 可以为网络分析图层的任意子图层添加字段。

语法

arcpy.na.AddFieldToAnalysisLayer(in_network_analysis_layer, sub_layer, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable})
参数说明数据类型
in_network_analysis_layer

要添加新字段的网络分析图层。

Network Analyst Layer
sub_layer

要添加新字段的网络分析图层的子图层。

String
field_name

要添加到网络分析图层的指定子图层中的字段名称。

String
field_type

在创建新字段时所使用的字段类型。

  • LONG — 在 -2,147,483,648 和 2,147,483,647 之间的整数。
  • TEXT —任何字符串。
  • FLOAT — 在 -3.4E38 和 1.2E38 之间的小数。
  • DOUBLE — 在 -2.2E308 和 1.8E308 之间的小数。
  • SHORT — 在 -32,768 和 32,767 之间的整数。
  • DATE —日期和/或时间。
  • BLOB —长二进制数序列。您需要一个自定义的加载器、查看器或第三方应用程序将这些项加载到 BLOB 字段中或者查看 BLOB 字段的内容。
String
field_precision
(可选)

可存储在字段中的位数。 所有位都将被计算在内,而无论其处于小数点的哪一侧。

参数值仅对数值字段类型有效。

Long
field_scale
(可选)

可存储在字段中的小数位数。 此参数仅在浮点型和双精度型数据字段类型中使用。

Long
field_length
(可选)

要添加的字段的长度。 它为字段的每条记录设置最大允许字符数。 此参数仅适用于文本类型的字段。

Long
field_alias
(可选)

指定给字段名称的备用名称。 此名称用于描述含义隐晦的字段名称。 此参数仅适用于地理数据库。

String
field_is_nullable
(可选)

指定该字段是否可包含空值。 空值不同于零或空字段,并且仅地理数据库中的字段支持空值。

  • NON_NULLABLE —字段不允许空值。
  • NULLABLE —字段允许空值。 这是默认设置。
Boolean

派生输出

名称说明数据类型
output_layer

已更新的网络分析图层。

网络分析图层

代码示例

向分析图层添加字段 (AddFieldToAnalysisLayer) 示例 1(Python 窗口)

下面的 Python 窗口脚本演示了如何将 UniqueID 字段添加到服务区网络分析图层的设施点子图层。

arcpy.na.AddFieldToAnalysisLayer("Service Area", "Facilities", "UniqueID",
                                    "LONG")
向分析图层添加字段 (AddFieldToAnalysisLayer) 示例 2(工作流)

下面的独立 Python 脚本演示了如何使用 AddFieldToAnalysisLayer 函数将 StationID 字段从输入的消防站要素传递到通过服务区分析计算出的 2、3、5 分钟服务区面要素。StationID 字段可用于将消防站要素的其他属性连接到服务区面要素。

# Name: AddFieldToAnalysisLayer_Workflow.py
# Description: Transfers the Address field from the input fire station 
#              features to the 2-,3-, and 5-minute service area polygon features
#              calculated from a service area analysis. The Address field can 
#              be used to join other attributes from the fire station features 
#              to the service area polygon features.
# 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/SanFrancisco.gdb"
    env.overwriteOutput = True
    
    #Set local variables
    inNetworkDataset = "Transportation/Streets_ND"
    outNALayerName = "FireStationsCoverage"
    impedanceAttribute = "TravelTime"
    defaultBreakValues = "2 3 5"   
    fieldName = "Address"
    fieldType = "TEXT"
    inFeatures = "Analysis/FireStations"
    searchTolerance = "2 Miles"
    outFeatures = outNALayerName + "Area"
    saFacilities = "Facilities"
    saPolygons = "SAPolygons"
    
    #Create a new service area analysis layer. For this scenario, the default 
    #value for all the remaining parameters statisfies the analysis requirements
    outNALayer = arcpy.na.MakeServiceAreaLayer(inNetworkDataset, outNALayerName,
                                               impedanceAttribute,"",
                                               defaultBreakValues)
    
    #Get the layer object from the result object. The service layer can now be
    #referenced using the layer object.
    outNALayer = outNALayer.getOutput(0)
    
    #Get the names of all the sublayers within the service area layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Stores the layer names that we will use later
    facilitiesLayerName = subLayerNames[saFacilities]
    polygonLayerName = subLayerNames[saPolygons]
    
    #Get the layer objects for all the sublayers within the service area layer
    #The first layer returned by ListLayers is the Service area layer itself
    #which we don't want to use.
    subLayers = {}
    for layer in arcpy.mapping.ListLayers(outNALayer)[1:]:
        subLayers[layer.datasetName] = layer
    #Store the layer objects that we will use later
    facilitiesLayer = subLayers[saFacilities]
    polygonLayer = subLayers[saPolygons]
    
    #Add a Address field to the Facilities sublayer of the service area layer.
    #This is done before loading the fire stations as facilities so that the 
    #Address values can be transferred from the input features to the 
    #Facilities sublayer. The service area layer created previously is 
    #referred by the layer object.
    arcpy.na.AddFieldToAnalysisLayer(outNALayer,facilitiesLayerName,fieldName,
                                     fieldType)
    
    #Add the fire station features as Facilities and map the Name and the 
    #Address properties from the Name and Address fields from fire station
    #features using the field mappings.
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, facilitiesLayerName)
    fieldMappings['Name'].mappedFieldName = "Name"
    fieldMappings['Address'].mappedFieldName = "Address"
    arcpy.na.AddLocations(outNALayer,facilitiesLayerName,inFeatures,
                          fieldMappings, searchTolerance)
    
    #Solve the service area layer
    arcpy.na.Solve(outNALayer)
    
    #Transfer the Address field from Facilities sublayer to Polygons sublayer 
    #of the service area layer since we wish to export the polygons. The 
    #FacilityID field in Polygons sub layer is related to the ObjectID field in
    #the Facilities sub layer. 
    arcpy.management.JoinField(polygonLayer, "FacilityID",facilitiesLayer,
                               "ObjectID", fieldName)
    
    #Export the Polygons sublayer to a feature class on disk.
    arcpy.management.CopyFeatures(polygonLayer, outFeatures)
    
    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 occurred on line %i" % tb.tb_lineno
    print str(e)

环境

  • 当前工作空间

许可信息

  • Basic: 是
  • Standard: 是
  • Advanced: 是

相关主题

  • 分析工具集概述

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2021 Esri. | 隐私政策 | 法律声明