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 字段支持存储为长度较长的一系列二进制数的数据。 您需要一个自定义的加载器、查看器或第三方应用程序将这些项加载到 BLOB 字段中或者查看 BLOB 字段的内容。
GUID—此字段类型将为 GUID。 GUID 字段可存储注册表样式的字符串,该字符串包含用大括号括起来的 36 个字符。
BIGINTEGER—此字段类型将为大整型。 大整型字段支持 -(253) 和 253 之间的整数。
TIMEONLY—此字段类型仅限时间。 仅时间字段支持不带日期值的时间值。
DATEONLY—此字段类型仅限日期。 仅日期字段支持不带时间值的日期值。
TIMESTAMPOFFSET—此字段类型将为时间戳偏移。 时间戳偏移字段支持日期、时间和相对于 UTC 值的偏移。
|
String
|
|
field_precision
(可选)
|
旧版本:
此参数已弃用,并将仅针对向后兼容性进行维护。
|
Long
|
|
field_scale
(可选)
|
旧版本:
此参数已弃用,并将仅针对向后兼容性进行维护。
|
Long
|
|
field_length
(可选)
|
字段长度。 它为字段的每条记录设置最大允许字符数。 如果未提供字段长度,则将使用长度 255。
字段长度仅适用于文本字段。
|
Long
|
|
field_alias
(可选)
|
该字段的备用名称。 此名称用于描述含义隐晦的字段名称。 此参数仅适用于地理数据库。
|
String
|
|
field_is_nullable
(可选)
|
指定该字段是否可包含空值。 空值不同于零字段或空字段,仅支持地理数据库中的字段。
|
Boolean
|
派生输出
|
名称
|
说明
|
数据类型
|
|
output_layer
|
已更新的网络分析图层。
|
Network Analyst Layer
|
代码示例
AddFieldToAnalysisLayer 示例 1(Python 窗口)
下面的 Python 窗口脚本演示了如何将 UniqueID 字段添加到服务区网络分析图层的设施点子图层。
arcpy.na.AddFieldToAnalysisLayer("Service Area", "Facilities", "UniqueID",
"LONG")
AddFieldToAnalysisLayer 示例 2(工作流)
下面的独立 Python 脚本演示了如何使用 AddFieldToAnalysisLayer 函数将 StationID 字段从输入的消防站要素传递到通过服务区分析计算出的 2、3、5 分钟服务区面要素。 StationID 字段可用于将消防站要素的其他属性连接到服务区面要素。
旧版本:
GetNASublayer 函数用于调用网络分析图层的子图层。 它在 ArcGIS Pro 2.7 中引入。 在以前的软件版本中,用于检索网络分析图层的子图层对象的最佳方法是使用网络分析 Layer 对象的 listLayers 方法,该方法将子图层名称用作通配符。
# 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
import os
try:
#Set environment settings
output_dir = "C:/Data"
#The NA layer's data will be saved to the workspace specified here
env.workspace = os.path.join(output_dir, "Output.gdb")
env.overwriteOutput = True
#Set local variables
input_gdb = "C:/Data/SanFrancisco.gdb"
network = os.path.join(input_gdb, "Transportation", "Streets_ND")
layer_name = "FireStationsCoverage"
travel_mode = "Driving Time"
cutoffs = [2, 3, 5] #minutes
field_to_add = "Address"
field_type = "TEXT"
facilities = os.path.join(input_gdb, "Analysis", "FireStations")
search_tolerance = "2 Miles"
out_featureclass = os.path.join(output_dir, "Output.gdb",
"FireStationsCoverageArea")
#Create a new service area analysis layer. For this scenario, the default
#value for all the remaining parameters statisfies the analysis requirements
result_object = arcpy.na.MakeServiceAreaAnalysisLayer(network, layer_name,
travel_mode, cutoffs=cutoffs)
#Get the layer object from the result object. The service area layer can now
#be referenced using the layer object.
layer_object = result_object.getOutput(0)
#Get the names of all the sublayers within the service area layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
facilities_layer_name = sublayer_names["Facilities"]
polygons_layer_name = sublayer_names["SAPolygons"]
#Add the 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.
arcpy.na.AddFieldToAnalysisLayer(layer_object, facilities_layer_name,
field_to_add, field_type)
#Add the fire station features as Facilities and map the Name and the
#Address fields from the fire station features to the Name and Address
#properties on the Facilities sublayer
field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
facilities_layer_name)
field_mappings['Name'].mappedFieldName = "Name"
field_mappings['Address'].mappedFieldName = "Address"
arcpy.na.AddLocations(layer_object, facilities_layer_name, facilities,
field_mappings, search_tolerance)
#Solve the service area layer
arcpy.na.Solve(layer_object)
#Get the layer objects for all the sublayers within the service area layer
facilities_sublayer = layer_object.listLayers(facilities_layer_name)[0]
polygons_sublayer = layer_object.listLayers(polygons_layer_name)[0]
#Transfer the Address field from the Facilities sublayer to the Polygons
#sublayer of the service area layer since we wish to export the polygons.
#The FacilityID field in the Polygons sublayer is related to the ObjectID
#field in the Facilities sublayer.
arcpy.management.JoinField(polygons_sublayer, "FacilityID",
facilities_sublayer, "ObjectID", field_to_add)
#Export the Polygons sublayer to a feature class on disk.
arcpy.management.CopyFeatures(polygons_sublayer, out_featureclass)
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))