Sunday 16 July 2017

Export all coded value domains from a geodatabase


On the ESRI-L mailing list this morning there was a question about how to see or export all the coded value domains for a geodatabase. The goal is to present the content of the domains in a tabular form, so they're easy to read.


The DomainToTable tool does this easily for a single domain, but when there are many domains it quickly grows tiresome. The best advice I could give was to the batch processing feature, but even that requires knowing or looking up the names of domains individually.


Surely there's a better way?



Answer



Here is something I put together that works on the simple gdb's I have on hand. I don't know how it might or might not handle sub-types with multiple domains (see Brent's comment).


Usage:


python export_gdb_domains.py [input geodatabase]


It exports the tables to the same gdb it's getting the domains from. It will fail if the table(s) exist already.


''' Export all coded value domains in a geodatabase to tables in that gdb '''
import os, sys
import arcpy

gdb = sys.argv[0]

desc = arcpy.Describe(gdb)
domains = desc.domains


for domain in domains:
print 'Exporting %s CV to table in %s' % (domain, gdb)
table = os.path.join(gdb, domain)
arcpy.DomainToTable_management(gdb, domain, table,
'field','descript', '#')

Updated version on github at https://github.com/envygeo/arcplus/blob/master/ArcToolbox/Scripts/export_gdb_domains.py. Optionally writes to XLS and overwrites existing tables.


Resources:






History


I initially tried to use an output directory and .csv files for the results instead, but kept getting "ERROR 000142: Field name in dBASE table cannot be longer than 10 characters". It seems to always interpret the path as part of the table name (c.f. table = line) {shrug}.


[Later]: @dgj32784 found the cause, 'description' at 11 characters is too long.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...