Attribuer un domaine à un champ (Gestion des données)

Récapitulatif

Définit le domaine d'un champ particulier et éventuellement d'un sous-type. Si aucun sous-type n'est précisé, le domaine est attribué uniquement au champ spécifié.

Utilisation

Syntaxe

AssignDomainToField_management (in_table, field_name, domain_name, {subtype_code})
ParamètreExplicationType de données
in_table

Nom de la table ou classe d'entités contenant le champ auquel un domaine sera attribué.

Table View
field_name

Nom du champ auquel un domaine sera attribué.

Field
domain_name

Nom d'un domaine de géodatabase à attribuer au nom du champ. Les domaines disponibles sont chargés automatiquement.

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

Code de sous-type à attribuer à un domaine.

String

Exemple de code

Exemple d'utilisation de l'outil AssignDomainToField (fenêtre Python)

Le script de fenêtre Python suivant illustre l'utilisation de l'outil AssignDomainToField en mode immédiat.

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.AssignDomainToField_management("montgomery.gdb/Landbase/Parcels", "ZONING_S", "ZoningFields", "1: government")
Exemple 2 d'utilisation de l'outil AssignDomainToField (script autonome)

Le script suivant utilise la fonction AssignDomainToField dans le cadre d'un workflow pour créer un domaine attributaire, affecter des valeurs au domaine et affecter le domaine à un champ.

# 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

Environnements

Rubriques connexes

Informations de licence

ArcView : Oui
ArcEditor : Oui
ArcInfo : Oui

7/10/2012