5

How can I check if a domain contains a particular coded value?

How to check if domain already exists? shows how to verify whether a domain exists in a geodatabase.

However, I can't see how to check that a particular coded value exists, before I use arcpy.DeleteCodedValueFromDomain_management

A workaround is to use Domain To Table and read the table - is that the best option?

def removeFromDomain(domain,value):
try:
 #Check if the coded value exists. For this we need to export the domain to a table, and read the table
 if arcpy.Exists(workspace + os.sep + tempTbl):
 arcpy.Delete_management(workspace + os.sep + tempTbl)
 arcpy.DomainToTable_management(workspace + os.sep + GDB, domain, workspace + os.sep + tempTbl, "code", "descript")
 rows = arcpy.SearchCursor(workspace + os.sep + tempTbl)
 valueExists = False
 for row in rows:
 if row.getValue("code") == value:
 valueExists = True
 if valueExists: 
 arcpy.DeleteCodedValueFromDomain_management(workspace + os.sep + GDB, domain, [value])
 print "Deleted coded value " + str(value) + " from domain " + str(domain)
 else:
 print "domain value " + str(value) + " does not exist on domain " + domain
 arcpy.Delete_management(workspace + os.sep + tempTbl)
except Exception, err:
 print err
 raise
asked Oct 3, 2012 at 22:55

2 Answers 2

5

You will need to be using ArcGIS 10.1 to use the da (Data Access) module but it looks like the Domain class has a codedValues property that can be used to obtain a Python dictionary containing the coded values for attribute domains.

answered Oct 3, 2012 at 23:26
1
  • Thanks, I'm currently stuck on 10.0 so I'll use my workaround for now and da once I can upgrade. Commented Oct 4, 2012 at 1:46
4

As @PolyGeo mentioned, If you are using 10.1, the arcpy.da (Data Access) module contains a ListDomains function which returns a list of Domain objects, each with a codedValues property you can examine to determine if the specified value exists in a given domain.

Alternatively, if this is an SDE geodatabase at version 10 or greater (in earlier versions, coded value domains were stored as BLOBs, while at 10 they are stored as XML), you could use SQL to to find the domain and its values.

answered Oct 3, 2012 at 23:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.