Ajouter une valeur codée à un domaine (Gestion des données)

Récapitulatif

Ajoute une valeur à une liste de valeurs précodées d'un domaine.

Utilisation

Syntaxe

AddCodedValueToDomain_management (in_workspace, domain_name, code, code_description)
ParamètreExplicationType de données
in_workspace

Géodatabase contenant le domaine à mettre à jour.

Workspace
domain_name

Nom du domaine attributaire dont la liste de valeurs précodées se voit ajouter une valeur.

String
code

Valeur à ajouter à la liste de valeurs précodées du domaine spécifié.

String
code_description

Description de ce que la valeur précodée représente.

String

Exemple de code

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

Le script de fenêtre Python ci-dessous illustre l'utilisation de la fonction AddCodedValueToDomain en mode immédiat.

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.AddCodedValueToDomain_management("montgomery.gdb", "material", "1", "PVC")
Exemple 2 d'utilisation de l'outil AddCodedValueToDomain (script autonome)

Ce script autonome utilise la fonction AddCodedValueToDomain dans le cadre d'un workflow pour créer un domaine attributaire et lui donner des valeurs.

# 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