Codierten Wert zu Domäne hinzufügen (Data Management)

Lizenzstufe:BasicStandardAdvanced

Zusammenfassung

Fügt einen Wert in die Liste codierter Werte einer Domäne ein.

Verwendung

Syntax

AddCodedValueToDomain_management (in_workspace, domain_name, code, code_description)
ParameterErläuterungDatentyp
in_workspace

Die Geodatabase, in der sich die zu aktualisierende Domäne befindet.

Workspace
domain_name

Der Name der Attributdomäne, deren Liste mit codierten Werten ein Wert hinzugefügt wird.

String
code

Der Wert, der der Liste mit codierten Werten für die angegebene Domäne hinzugefügt wird.

String
code_description

Eine Beschreibung des codierten Wertes.

String

Codebeispiel

AddCodedValueToDomain – Beispiel (Python-Fenster)

Im folgenden Skript im Python-Fenster wird veranschaulicht, wie Sie die Funktion "AddCodedValueToDomain" im unmittelbaren Modus verwenden.

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.AddCodedValueToDomain_management("montgomery.gdb", "material", "1", "PVC")
AddCodedValueToDomain – Beispiel 2 (eigenständiges Skript)

In diesem eigenständigen Skript wird die Funktion "AddCodedValueToDomain" als Teil eines Workflows verwendet, um eine Attributdomäne zu erstellen und dieser Werte zuzuweisen.

# 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

Umgebung

Verwandte Themen

Lizenzierungsinformationen

ArcGIS for Desktop Basic: Ja
ArcGIS for Desktop Standard: Ja
ArcGIS for Desktop Advanced: Ja
5/9/2014