Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

ArcMap has the ability to show an extended description for each item in the symbol list. How can I populate that property from a table? The goal is to avoid having to edit each symbol one by one in order to add the description.

enter image description here

share|improve this question

3 Answers 3

up vote 7 down vote accepted

Rather than try to use the ArcMap application alone, I have brought ArcPy into the picture.

I just tested and achieved what you described using the UniqueValuesSymbology (arcpy.mapping) class which has a writable classDescriptions property which can be set to:

A list of strings or numbers that represent the descriptions for each unique value that can optionally appear in a map document's legend. These values are only accessible in the ArcMap user interface by right-clicking a symbol displayed within the Symbology tab in the Layer Properties dialog box and selecting Edit Description. The classDescriptions list needs to have the same number of elements and arranged in the same order as the classValues property.

The code uses a Search Cursor to read the lookup table into a list, and then writes that list to the classDescriptions property of the layer's symbology class. Note that the lookup table MUST have the same number of rows and be in the same order as the values of the unique symbology classification. My code would need to be enhanced to account for that not being the case but making sure of that order manually was easy in my test case.

import arcpy

vegDescList = []
vegCodes = arcpy.SearchCursor(r"C:\temp\test.gdb\LookupTable")
for vegCode in vegCodes:
    vegDescList.append(vegCode.Description)

mxd = arcpy.mapping.MapDocument(r"C:\temp\test.mxd")
lyr = arcpy.mapping.ListLayers(mxd,"testFC")[0]
if lyr.symbologyType == "UNIQUE_VALUES":
    lyr.symbology.classDescriptions = vegDescList
mxd.save()

del mxd
share|improve this answer
    
I put together some test code to see if this would work and although no errors are generated the updated descriptions don't make it back to the layer. I'm new to arcpy in mapping so it's probably something I've done wrong. –  Michael Miles-Stimson Jun 23 at 23:46
    
does that work? I've got much the same except I'm using MapDocument("current") and RefreshActiveView()/RefreshTOC() but nothing gets updated. –  Michael Miles-Stimson Jun 24 at 0:15
1  
@MichaelMiles-Stimson Yes - it updated as intended - I suspect that what you have missed is that it is not the TOC which shows the Description values but a Legend Layout Element. Insert one of those and choose a Legend Item Style that displays Descriptions and I think it will become clear that it does work. –  PolyGeo Jun 24 at 0:22
    
Thank you @polygeo! That is exactly it! It was doing it all along I was just looking in the wrong place. –  Michael Miles-Stimson Jun 24 at 0:28
    
I solved the problem of having to make descriptions and lookup codes match, see my answer. –  matt wilkie Jul 4 at 21:34

Could you classify your symbols with "Unique Values Many Fields" and choose one field for the code and the second for the longer description? That should label each item with a string in the form "[Field1], [Field2]"

It works with smaller fields, I imagine it would with longer strings, unless there is a limitation I'm not familiar with.

The only annoying part would be that you may have to go through and delete the code value from the beginning of the label value, but that wouldn't be the worst thing that had ever happened.

share|improve this answer
    
An interesting idea that might work in some situations. It won't work here though because the description table is just a table, there is no geometry. One could join the geometry and descriptions, but I'm not interested in that extra work or performance hit for this project. –  matt wilkie Jun 24 at 15:48

Working from PolyGeo's code, here's what I came up with to work around the problem of having to have an exact number of items and identical order match between lookup values and the description. The full working script is here.

# name and path of the lookup table
lookup_table = r"..\default.gdb\vegMajorComm_Lookup"

# change these to match the relevant field names in the lookup table
code = 'VegCode'
description = 'Description'

##...snip...

# build the descriptions dictionary
descriptions = {}
rows = arcpy.SearchCursor(lookup_table)
for item in rows:
    #print item.getValue(code), item.getValue(description)
    descriptions[item.getValue(code)] = item.getValue(description)

# lyr.symbology requires the classValues and classDescriptions to have
# same number of rows and be in same order. So extract only matching 
# elements from the description dictionary
desclist = []
if lyr.symbologyType == "UNIQUE_VALUES":

    #extract matches
    for symbol in lyr.symbology.classValues:
      desclist.append(descriptions[symbol])    

    # assign the descriptions
    lyr.symbology.classDescriptions = desclist

mxd.saveACopy(output_map)
del mxd
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.