arcpy.management.CreateDomain(in_workspace, domain_name, {domain_description}, {field_type}, {domain_type}, {split_policy}, {merge_policy})
|
名称
|
说明
|
数据类型
|
|
in_workspace
|
将包含新属性域的地理数据库。
|
Workspace
|
|
domain_name
|
要创建的属性域的名称。
|
String
|
|
domain_description
(可选)
|
要创建的属性域的描述。
|
String
|
|
field_type
(可选)
|
指定要创建的属性域的类型。 属性域属性是描述字段类型允许值的规则。 指定的字段类型应与将属性域指定到的字段的数据类型相匹配。
SHORT—此字段类型将为短整型。 短整型字段支持介于 -32,768 和 32,767 之间的整数。
LONG—此字段类型将为长整型。 长整型字段支持介于 -2,147,483,648 和 2,147,483,647 之间的整数。
BIGINTEGER—此字段类型将为大整型。 大整型字段支持 -(253) 和 253 之间的整数。
FLOAT—此字段类型将为浮点型。 浮点型字段支持介于 -3.4E38 和 1.2E38 之间的小数。
DOUBLE—此字段类型将为双精度型。 双精度型字段支持介于 -2.2E308 和 1.8E308 之间的小数。
TEXT—此字段类型将为文本类型。 文本字段支持字符串。
DATE—此字段类型将为日期类型。 日期字段支持日期和时间值。
DATEONLY—此字段类型仅限日期。 仅日期字段支持不带时间值的日期值。
TIMEONLY—此字段类型仅限时间。 仅时间字段支持不带日期值的时间值。
|
String
|
|
domain_type
(可选)
|
指定要创建的属性域的类型。
|
String
|
|
split_policy
(可选)
|
指定将用于所创建属性域的分割策略。 分割要素时,属性值的行为受控于它的分割策略。
DEFAULT—两个结果要素的属性将使用给定要素类或子类型的默认属性值。
DUPLICATE—两个结果要素的属性使用原始对象的属性值副本。
GEOMETRY_RATIO—结果要素的属性将是原始要素值的比率。 该比率取决于原始几何的分割比例。 如果几何被分割成相等的两部分,则每个新要素的属性值将是原始对象属性值的一半。 几何比策略仅适用于范围属性域。
|
String
|
|
merge_policy
(可选)
|
指定将用于所创建属性域的合并策略。 在将两个要素合并为一个要素时,合并策略控制着新要素的属性值。
DEFAULT—结果要素的属性将使用给定要素类或子类型的默认属性值。 这是唯一适用于非数字字段和编码值属性域的合并策略。
SUM_VALUES—结果要素的属性将使用原始要素属性值的总和。 总和值策略仅适用于范围属性域。
AREA_WEIGHTED—结果要素的属性将使用原始要素属性值的加权平均值。 此平均值取决于原始要素的几何。 加权面积策略仅适用于范围属性域。
|
String
|
派生输出
|
名称
|
说明
|
数据类型
|
|
out_workspace
|
已更新的输入工作空间。
|
Workspace
|
代码示例
CreateDomain 示例 1(Python 窗口)
以下 Python 窗口脚本演示了如何在即时模式下使用 CreateDomain 函数。
import arcpy
arcpy.env.workspace = "C:/data"
arcpy.management.CreateDomain("montgomery.gdb", "Materials",
"Valid pipe materials", "TEXT", "CODED")
此独立脚本将 CreateDomain 函数用作工作流的一部分,以创建属性域、为其赋值并将属性域分配给要素类的字段。
# 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 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)