Thursday, March 18, 2010

Listing Domains

Here is a handy little Python script which lists all the domains in a GeoDatabase, then exports each to a table within that GeoDatabase.

import arcgisscripting
gp = arcgisscripting.create(9.3)
ws = "c:\\temp\\test.gdb"
desc = gp.describe(ws)
print "Domains in '%s': " % ws
domains = desc.Domains
for domain in domains:
print domain
gp.DomainToTable(ws, domain, ws + "\\domain_" + domain , "CODE", "DESCRIPTION")

To run the script:
  1. Open up a Python Editor, such as PyScripter or PythonWin
  2. Copy the above code to a script file
  3. Make sure there is a tab before the print domain, and gp.DomainToTable(... lines (it doesn't seemed to include tabs properly in the blog posts).
  4. Update the ws variable to the GeoDatabase you wish to analyse
  5. Click run
Notes:
  • The output tables are named "domain_XXX" where XXX is the name of the domain
  • Each of these tables have two fields: one called CODE, which lists the code and a second called DESCRIPTION which lists the description.

No comments: