ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Assign Domain To Field

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

Sets the domain for a particular field and, optionally, for a subtype. If no subtype is specified, the domain is only assigned to the specified field.

Usage

  • Domain management involves the following steps:

    1. Create the domain using the Create Domain tool.
    2. Add values to or set the range of values for the domain using the Add Coded Value to Domain tool or Set Value For Range Domain tool.
    3. Associate the domain with a feature class using this tool.
  • When an attribute domain is associated with a table or feature class, an attribute validation rule is created in the database. This attribute validation rule describes and constrains the valid values of a field type.

  • One attribute domain can be associated with multiple fields in the same table, feature class, or subtype as well as in multiple tables and feature classes.

  • The Input Table parameter accepts feature layers or table views.

  • Workspace domains can also be managed in ArcCatalog or the Catalog window. Domains can be created and modified through the Domains tab on the Database Properties dialog box.

  • The Subtype parameter Add Value button is used only in ModelBuilder. In ModelBuilder, where the preceding tool has not been run, or its derived data does not exist, the Subtype parameter may not be populated with values. The Add Value button allows you to add expected values so you can complete the Assign Domain To Field dialog and continue to build your model.

Syntax

AssignDomainToField_management (in_table, field_name, domain_name, {subtype_code})
ParameterExplanationData Type
in_table

The name of the table or feature class containing the field that will be assigned a domain.

Table View
field_name

The name of the field to be assigned a domain.

Field
domain_name

The name of a geodatabase domain to assign to the field name. Available domains will automatically be loaded.

String
subtype_code
[subtype_code,...]
(Optional)

The subtype code to be assigned a domain.

String

Code sample

Assign Domain to Field Example (Python Window)

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

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 Example 2 (Stand-alone Script)

The following script uses the AssignDomainToField function as part of a workflow to create an attribute domain, assign values to the domain, and assign the domain to a field.

# Name: MakeDomain.py
# Description: Create an attribute domain to constrain pipe material values
 
#Import system modules
import arcpy
 
try:
    # 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)
 
except Exception as err:
    print(err.args[0])

Environments

  • Auto Commit
  • Current Workspace

Licensing information

  • ArcGIS for Desktop Basic: Yes
  • ArcGIS for Desktop Standard: Yes
  • ArcGIS for Desktop Advanced: Yes

Related topics

  • An overview of the Domains toolset
  • A quick tour of subtypes
  • A quick tour of attribute domains
  • Geoprocessing considerations for attribute domains
  • Working with layers and table views

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal