arcpy.management.AssignDomainToField(in_table, field_name, domain_name, {subtype_code})
|
名称
|
说明
|
数据类型
|
|
in_table
|
包含要指定属性域的字段的表或要素类的名称。
|
Table View
|
|
field_name
|
将指定属性域的字段的名称。
|
Field
|
|
domain_name
|
将指定给字段名的地理数据库属性域的名称。 将自动加载可用的属性域。
|
String
|
|
subtype_code
[subtype_code,...]
(可选)
|
将指定属性域的子类型编码。
|
String
|
派生输出
|
名称
|
说明
|
数据类型
|
|
out_table
|
更新的输入表。
|
Table View
|
代码示例
AssignDomainToField 示例 1(Python 窗口)
以下 Python 窗口脚本演示了如何在即时模式下使用 AssignDomainToField 函数。
import arcpy
arcpy.env.workspace = "C:/data"
arcpy.management.AssignDomainToField("montgomery.gdb/Landbase/Parcels",
"ZONING_S", "ZoningFields", "1: government")
AssignDomainToField 示例 2(独立脚本)
以下脚本将 AssignDomainToField 函数用作工作流的一部分,以创建属性域、为属性域指定值并为字段指定属性域。
# Name: MakeDomain.py
# Description: Create an attribute domain to constrain pipe material values
# 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"
# Set local parameters
domName = "Material4"
gdb = "montgomery.gdb"
inFeatures = "Montgomery.gdb/Water/Distribmains"
inField = "Material"
# Process: Create the coded value domain
arcpy.management.CreateDomain("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.management.AddCodedValueToDomain(gdb, domName, code, domDict[code])
# Process: Constrain the material value of distribution mains
arcpy.management.AssignDomainToField(inFeatures, inField, domName)