arcpy.management.AddSubtype(in_table, subtype_code, subtype_description)
|
名称
|
说明
|
数据类型
|
|
in_table
|
要更新的子类型定义所在的要素类或表。
|
Table View
|
|
subtype_code
|
要添加的子类型的唯一整数值。
|
Long
|
|
subtype_description
|
子类型编码的名称(也称为描述)。
|
String
|
派生输出
|
名称
|
说明
|
数据类型
|
|
out_table
|
已更新的表或要素类。
|
Table View
|
代码示例
AddSubtype 示例 1(Python 窗口)
以下 Python 窗口脚本演示了如何在即时模式下使用 AddSubtype 函数。
import arcpy
arcpy.env.workspace = "C:/data/Montgomery.gdb"
arcpy.management.SetSubtypeField("water/fittings", "TYPECODE")
arcpy.management.AddSubtype("water/fittings", "1", "Bend")
以下独立脚本演示了如何在将子类型添加到字段的工作流中使用 AddSubtype 函数。
# Name: ManageSubtypes.py
# Purpose: Create a subtype definition
# Import system modules
import arcpy
# Set the workspace (to avoid having to type in the full path to the data every time)
arcpy.env.workspace = "C:/data/Montgomery.gdb"
# Set local parameters
inFeatures = "water/fittings"
# Process: Set Subtype Field...
arcpy.management.SetSubtypeField(inFeatures, "TYPECODE")
# Process: Add Subtypes...
# Store all the suptype values in a dictionary with the subtype code as the
# "key" and the subtype name as the "value" (stypeDict[code])
stypeDict = {"0": "Unknown", "1": "Bend", "2": "Cap", "3": "Cross",
"4": "Coupling", "5": "Expansion joint", "6": "Offset",
"7": "Plug", "8": "Reducer", "9": "Saddle", "10": "Sleeve",
"11": "Tap", "12": "Tee", "13": "Weld", "14": "Riser"}
# use a for loop to cycle through the dictionary
for code in stypeDict:
arcpy.management.AddSubtype(inFeatures, code, stypeDict[code])
# Process: Set Default Subtype...
arcpy.management.SetDefaultSubtype(inFeatures, "4")
以下脚本使用 try/except 块来处理当字段已包含子类型代码时 'AddSubtype' 函数返回的错误。
# Name: ManageSubtypes2.py
# Purpose: Add more subtype definitions
# Import system modules
import arcpy
# Set the workspace (to avoid having to type in the full path to the data every time)
arcpy.env.workspace = "C:/data/Montgomery.gdb"
# Set local parameters
inFeatures = "water/fittings"
# Define new subtypes to be added
# Store all the suptype values in a dictionary with the subtype code as the
# "key" and the subtype name as the "value" (stypeDict[code])
stypeDict = { "5": "Expansion joint", "6": "Offset", "7": "Plug",
"8": "Reducer", "9": "Saddle", "10": "Sleeve",
"11": "Tap", "12": "Tee", "13": "Weld", "14": "Riser"}
# Process: Add Subtypes...
# use a for loop to cycle through the dictionary
# use a try/except to catch errors from any subtypes that already exist on the field
for code in stypeDict:
try:
arcpy.management.AddSubtype(inFeatures, code, stypeDict[code])
except:
print(f"Skipping '{code}: {stypeDict[code]}' as it is already a subtype on the field.")