Select to view content in your preferred language

Storing domian coded values in a dictionary

440
3
Jump to solution
05-03-2023 06:19 AM
kumarprince8071
New Contributor III

How to store the arcpy.da.ListDomains(gdb) domaincoded values inside a dictionary using python/arcpy

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Can you be more specific? What are you trying to do with the "stored" domain? Does it need to be in any particular format?

Once you get the list of domains from arcpy.da.ListDomains, you should just be able to iterate through the response and do whatever you need it to.

doms = arcpy.da.ListDomains('some gdb')

dom_dict = {}

for d in doms:
    dom_dict[d.name] = {
        'type': d.domainType,
        'codedValues': d.codedValues,
        'range': d.range
    }

 

- Josh Carlson
Kendall County GIS

View solution in original post

3 Replies
jcarlson
MVP Esteemed Contributor

Can you be more specific? What are you trying to do with the "stored" domain? Does it need to be in any particular format?

Once you get the list of domains from arcpy.da.ListDomains, you should just be able to iterate through the response and do whatever you need it to.

doms = arcpy.da.ListDomains('some gdb')

dom_dict = {}

for d in doms:
    dom_dict[d.name] = {
        'type': d.domainType,
        'codedValues': d.codedValues,
        'range': d.range
    }

 

- Josh Carlson
Kendall County GIS
kumarprince8071
New Contributor III

Suppose i get the codedValues from arcpy.da.ListDomains(gdb) by iterating over it then in codedValues we get code and value like a dictionary of values {0:'value1',1:'value2'} so i want to store this dictionary value into another dictionary from i can access these values as key,value .

0 Kudos
jcarlson
MVP Esteemed Contributor

You could do that. You'd have to be careful, in case there were duplicate codes in your database.

values_dict = {}

for d in doms:
    for c in d.codedValues:
        values_dict[c] = d.codedValues[c]
- Josh Carlson
Kendall County GIS
0 Kudos