フィールドへのドメインの割り当て(Assign Domain To Field) (データの管理)

サマリ

特定のフィールドおよび必要に応じてサブタイプにドメインを設定します。サブタイプを指定しなかった場合は、指定したフィールドのみにドメインが割り当てられます。

使用法

構文

AssignDomainToField_management (in_table, field_name, domain_name, {subtype_code})
パラメータ説明データ タイプ
in_table

ドメインを割り当てるフィールドが含まれているテーブルまたはフィーチャクラスの名前

Table View
field_name

ドメインを割り当てるフィールドの名前

Field
domain_name

フィールド名に割り当てるジオデータベース ドメインの名前。使用可能なドメインが自動的に読み込まれます。

String
subtype_code
[subtype_code,...]
(オプション)

ドメインを割り当てるサブタイプのコード

String

コードのサンプル

Assign Domain to Field (フィールドへのドメインの割り当て)の例 (Python ウィンドウ)

次の Python ウィンドウ スクリプトで、AssignDomainToField (フィールドへのドメインの割り当て)関数をイミディエイト モードで使用する方法を示します。

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.AssignDomainToField_management("montgomery.gdb/Landbase/Parcels", "ZONING_S", "ZoningFields", "1: government")
Assign Domain to Field (フィールドへのドメインの割り当て)の例 2(スタンドアロン スクリプト)

次のスクリプトでは、AssignDomainToField (フィールドへのドメインの割り当て)関数をワークフローの一部として使用することにより、属性ドメインを作成し、このドメインに値を割り当て、このドメインをフィールドに割り当てます。

# Name: MakeDomain.py
# Description: Create an attribute domain to constrain pipe material values
# Author: ESRI

 
#Import system modules
import arcpy
from arcpy import env
 
try:
    # Set the workspace (to avoid having to type in the full path to the data every time)
    env.workspace = "C:/data"
 
    # Set local parameters
    domName = "Material4"
    gdb = "montgomery.gdb"
    inFeatures = "Montgomery.gdb/Water/Distribmains"
    inField = "Material"
 
    # Process: Create the coded value domain
    arcpy.CreateDomain_management("montgomery.gdb", domName, "Valid pipe materials", "TEXT", "CODED")
    
    #Store all the domain values in a dictionary with the domain code as the "key" and the 
    #domain description as the "value" (domDict[code])
    domDict = {"CI":"Cast iron", "DI": "Ductile iron", "PVC": "PVC", \
                "ACP": "Asbestos concrete", "COP": "Copper"}
    
    # Process: Add valid material types to the domain
    #use a for loop to cycle through all the domain codes in the dictionary
    for code in domDict:        
        arcpy.AddCodedValueToDomain_management(gdb, domName, code, domDict[code])
    
    # Process: Constrain the material value of distribution mains
    arcpy.AssignDomainToField_management(inFeatures, inField, domName)
 
except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message

環境

関連項目

ライセンス情報

ArcView: はい
ArcEditor: はい
ArcInfo: はい

7/10/2012