The Main, De Main, Duh Main, Doh Main, Domain
In many of the workflows we automate much of the effort is around development of a good data model that encapsulates the workflow inputs and outputs and provides a level of consistency that (usually) is not already in place. Domains within a geodatabase are awesome for ensuring consistency within data models and for easing the effort (and improving consistency) for data management and maintenance. No shortage of good merits for domains both coded and range alike.
When you work with domains often enough through Python you quickly come across some limitations on usability, or perhaps better stated, you come across the ways that you want to use it that aren’t readily exposed to Python. Here are some simple use cases we run into all the time.
>>> from pygp.dataelement.extended import GeodatabaseWorkspace
>>> # Open up a geodatabase in a case insensitive state
>>> gdb = GeodatabaseWorkspace(GDB_PATH_NAME, nocase=True)
>>> # Use case #1: Check if a domain exists in a geodatabase
>>> domain_name = 'test_domain_name'
>>> domain_name in gdb.domains
True
>>> # Use case #2: Get a domain from a field in a table
>>> field = table.fields['MY_FIELD_NAME']
>>> domain = field.domain
>>> # Use Case #3: What type of domain is this?
>>> # Only two types of domains, coded and range
>>> domain.is_range
True
>>> # Use Case #4: Is the value ok for the Domain?
>>> 1000 in domain
False
>>> 5 in domain
True