[GIS] Populate a layout text element with the description from a coded value domain

arcgis-10.1arcpyattribute-joinsdomainsdynamic

ArcGIS 10.1+ lets you easily put dynamically populated text boxes in your print layouts. Doing so puts some text in the text element that looks something like this:

<dyn type="page" property="attribute" field="sampleTable.sampleAttribute"domainlookup="true"/>

It works fine for me when I have it just pulls from the index feature class. My problem is that I have data in other feature classes in the same database that need to be joined to the index layer so I can pull relevant attributes out of there and display them in other text elements. As soon as I join one of those feature classes to the index feature class the domain lookup no longer works regardless of what it is set to. That is to say I only get the coded values in my text elements. ESRI has logged this bug (#NIM104451), but I need a workaround sooner than when (if) they get around to fixing it.

My first thought was to use some python to take care of this, but it's getting more unwieldy the more I think about it. My general thought process is this:

  • Make sure the text elements I want to use share the name of the domain they will pull from
  • List layout elements
    List domains in the database
  • For every layout element, step through the domain list until the domain equals the element name
  • Take the current element text (the coded value) and replace it with the equivalent description from the domain

I got this far in my code before thinking there has to be a more efficient way:

import arcpy
mxd = samplemxd

domains = arcpy.da.ListDomains("Database Connections\\database.sde")

Elements = arcpy.listlayoutelements(mxd)

For elem in Elements:
    for dmn in domains:
        if elem.name == dmn.name:
            coded_values = domain.codedValues
            for val, desc in coded_values.iteritems():
                if val == !layer.attribute!
                    elem.text = desc

Any ideas? I'm open to non-python ideas as well, in case there's something database side I can do.

Best Answer

Okay, posting for posterity's sake now.

My team and I did find a way to successfully implement data driven pages with domain values (for the ultimate purpose of a printing service) using a combination of python and spatial views that were created in the database. Basically, every field I wanted on the print layout was included in the spatial view. The python still looped through element names and domain lists as I described above.

The problem with this is that it's abominably slow. We didn't want our end users to wait a solid minute or more (depending on number of pages) for any response from the print button.

The eventual solution we settled on is much simpler and faster. We have the print button generating an html page that pulls data from the database and formats it in pretty much an exact replica of the .mxd we were using. For the map it uses a function on the rest endpoint to generate an image from the map service.

Related Question