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 の例 2 (スタンドアロン スクリプト)
次のスタンドアロン スクリプトは、サブタイプをフィールドに追加するワークフローの一部として、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")
AddSubtype の例 3 (スタンドアロン スクリプト)
以下のスクリプトでは、フィールドにすでにサブタイプコードが存在する場合に 'AddSubtype' 関数から返されるエラーを処理するために try/except ブロックが使用されます。
# 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.")