Domäne zu Feld zuweisen (Data Management)

Lizenzstufe:BasicStandardAdvanced

Zusammenfassung

Legt die Domäne für ein bestimmtes Feld und optional für einen Subtype fest. Wenn kein Subtype angegeben ist, wird die Domäne nur dem angegebenen Feld zugewiesen.

Verwendung

Syntax

AssignDomainToField_management (in_table, field_name, domain_name, {subtype_code})
ParameterErläuterungDatentyp
in_table

Der Name der Tabelle oder Feature-Class mit dem Feld, dem eine Domäne zugewiesen wird

Table View
field_name

Der Name des Feldes, dem eine Domäne zugewiesen wird

Field
domain_name

Der Name einer Geodatabase-Domäne, die dem Feldnamen zugewiesen wird. Alle verfügbaren Domänen werden automatisch geladen.

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

Der Subtype-Code, dem eine Domäne zugewiesen wird.

String

Codebeispiel

Assign Domain to Field – Beispiel (Python-Fenster)

Das folgende Skript im Python-Fenster zeigt, wie die Funktion "AssignDomainToField" im unmittelbaren Modus verwendet wird.

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 – Beispiel 2 (eigenständiges Skript)

Im folgenden Skript wird die Funktion "AssignDomainToField" als Teil eines Workflows verwendet, um eine Attributdomäne zu erstellen, dieser Werte zuzuweisen und die Domäne einem Feld 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