Create Domain (Data Management)

Summary

Creates an attribute domain in the specified workspace.

Usage

  • Domain management involves the following:

    1. Create the domain using the this tool.
    2. Add values to or set the range of values for the domain using the Add Coded Value to Domain or Set Value For Range Domain tool.
    3. Associate the domain with a feature class using the Assign Domain To Field tool.
  • Coded value domains support only default value and duplicate split policies and default value merge policies.

  • Range domains support all split and merge policies. After a split or merge operation, the attribute values of output features are calculated based on the numeric values of the input features and the specified split or merge policy.

Parameters

LabelExplanationData Type
Input Workspace

The geodatabase that will contain the new domain.

Workspace
Domain Name

The name of the domain that will be created.

String
Domain Description
(Optional)

The description of the domain that will be created.

String
Field Type
(Optional)

Specifies the type of attribute domain that will be created. Attribute domains are rules that describe the accepted values of a field type. Specify a field type that matches the data type of the field to which the attribute domain will be assigned.

  • TextA text type field will be created that contains a string of characters.
  • Float (single precision) A float type field will be created that contains fractional numbers between -3.4E38 and 1.2E38.
  • Double (double precision) A double type field will be created that contains fractional numbers between -2.2E308 and 1.8E308.
  • Short (small integer) A short type field will be created that contains whole numbers between -32,768 and 32,767.
  • Long (large integer) A long type field will be created that contains whole numbers between -2,147,483,648 and 2,147,483,647.
  • DateA date type field will be created that contains a date and/or time.
String
Domain Type
(Optional)

Specifies the domain type that will be created.

  • Coded value domainA coded type domain will be created that contains a valid set of values for an attribute. This is the default. For example, a coded value domain can specify valid pipe material values such as CL—cast iron pipe, DL—ductile iron pipe, or ACP—asbestos concrete pipe.
  • Range domainA range type domain will be created that contains a valid range of values for a numeric attribute. For example, if distribution water mains have a pressure between 50 and 75 psi, a range domain specifies these minimum and maximum values.
String
Split Policy
(Optional)

Specifies the split policy that will be used for the created domain. The behavior of an attribute's values when a feature that is split is controlled by its split policy.

  • Use the attribute's default valueThe attributes of the two resulting features will use the default value of the attribute of the given feature class or subtype.
  • Duplicate attribute valuesThe attribute of the two resulting features will use a copy of the original object's attribute value.
  • Use geometric ratioThe attributes of resulting features will be a ratio of the original feature's value. The ratio is based on the proportion into which the original geometry is divided. If the geometry is divided equally, each new feature's attribute gets one-half the value of the original object's attribute. The geometry ratio policy only applies to range domains.
String
Merge Policy
(Optional)

Specifies the merge policy that will be used for the created domain. When two features are merged into a single feature, merge policies control attribute values in the new feature.

  • Use the attribute's default valueThe attribute of the resulting feature will use the default value of the attribute of the given feature class or subtype. This is the only merge policy that applies to nonnumeric fields and coded value domains.
  • Sum of the valuesThe attribute of the resulting feature will use the sum of the values from the original feature's attribute. The sum values policy only applies to range domains.
  • Area weighted averageThe attribute of the resulting feature will be the weighted average of the attribute values of the original features. This average is based on the original feature's geometry. The area weighted policy only applies to range domains.
String

Derived Output

LabelExplanationData Type
Updated Input Workspace

The updated input workspace.

Workspace

arcpy.management.CreateDomain(in_workspace, domain_name, {domain_description}, {field_type}, {domain_type}, {split_policy}, {merge_policy})
NameExplanationData Type
in_workspace

The geodatabase that will contain the new domain.

Workspace
domain_name

The name of the domain that will be created.

String
domain_description
(Optional)

The description of the domain that will be created.

String
field_type
(Optional)

Specifies the type of attribute domain that will be created. Attribute domains are rules that describe the accepted values of a field type. Specify a field type that matches the data type of the field to which the attribute domain will be assigned.

  • TEXTA text type field will be created that contains a string of characters.
  • FLOAT A float type field will be created that contains fractional numbers between -3.4E38 and 1.2E38.
  • DOUBLE A double type field will be created that contains fractional numbers between -2.2E308 and 1.8E308.
  • SHORT A short type field will be created that contains whole numbers between -32,768 and 32,767.
  • LONG A long type field will be created that contains whole numbers between -2,147,483,648 and 2,147,483,647.
  • DATEA date type field will be created that contains a date and/or time.
String
domain_type
(Optional)

Specifies the domain type that will be created.

  • CODEDA coded type domain will be created that contains a valid set of values for an attribute. This is the default. For example, a coded value domain can specify valid pipe material values such as CL—cast iron pipe, DL—ductile iron pipe, or ACP—asbestos concrete pipe.
  • RANGEA range type domain will be created that contains a valid range of values for a numeric attribute. For example, if distribution water mains have a pressure between 50 and 75 psi, a range domain specifies these minimum and maximum values.
String
split_policy
(Optional)

Specifies the split policy that will be used for the created domain. The behavior of an attribute's values when a feature that is split is controlled by its split policy.

  • DEFAULTThe attributes of the two resulting features will use the default value of the attribute of the given feature class or subtype.
  • DUPLICATEThe attribute of the two resulting features will use a copy of the original object's attribute value.
  • GEOMETRY_RATIOThe attributes of resulting features will be a ratio of the original feature's value. The ratio is based on the proportion into which the original geometry is divided. If the geometry is divided equally, each new feature's attribute gets one-half the value of the original object's attribute. The geometry ratio policy only applies to range domains.
String
merge_policy
(Optional)

Specifies the merge policy that will be used for the created domain. When two features are merged into a single feature, merge policies control attribute values in the new feature.

  • DEFAULTThe attribute of the resulting feature will use the default value of the attribute of the given feature class or subtype. This is the only merge policy that applies to nonnumeric fields and coded value domains.
  • SUM_VALUESThe attribute of the resulting feature will use the sum of the values from the original feature's attribute. The sum values policy only applies to range domains.
  • AREA_WEIGHTEDThe attribute of the resulting feature will be the weighted average of the attribute values of the original features. This average is based on the original feature's geometry. The area weighted policy only applies to range domains.
String

Derived Output

NameExplanationData Type
out_workspace

The updated input workspace.

Workspace

Code sample

CreateDomain example 1 (Python window)

The following Python window script demonstrates how to use the CreateDomain function in immediate mode.

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.CreateDomain_management("montgomery.gdb", "Materials", 
                              "Valid pipe materials", "TEXT", "CODED")
CreateDomain example 2 (stand-alone script)

This stand-alone script uses the CreateDomain function as part of a workflow to create an attribute domain, assign values to it, and assign the domain to a field in a feature class.

# 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.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)

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics