ArcMap – Labeling Map Legend w/ 2nd Attribute Table Records

Here is a little problem I’ve been having in ArcMap: When I create a geology map, I am using a geodatabase with the Geologic Atlas of Texas (GAT_250K-es.mdb) that contains digitized rock units and faults. This allows me to create great looking geology maps all over the State of Texas. A second geodatabase (GAT_Rockunit_Tables.mdb) includes additional attributes of the units and formations included in the first one, such as a description of the lithology.

What I would like to do but have been unable to figure out up to this point is to plot and label my geologic units on a map using MDB#1 but then label them in the legend using an attribute from MDB#2. It’s easy to join the two tables. But I can’t figure out, how to label the legend without also changing the labeling on the map. On the symbology table of the rock unit layer, you can enter a description for each record which then appears in the legend behind the actual label (in italics). I would be happy doing that if it weren’t such a pain to manually enter all these descriptions. Is there a shortcut to this ? I can’t seem to find it.

legendlabel

Advertisements

2 Comments

Filed under Uncategorized

2 responses to “ArcMap – Labeling Map Legend w/ 2nd Attribute Table Records

  1. opinisaya

    how to create like that with VBA?

  2. dhardy

    I’m guessing you may have solved this by now. However, if not, here’s some code that should work.

    The function assumes you have a table of unique codes and descriptions in an Access database. Using DAO, it’s not a very ‘ArcObjects’ way to get the information but it works.

    Just changed the hard coded table name and field name in the sql statement, and the field name whose value you want to return.

    Sub SetRendererDescriptions()

    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument

    Dim pMap As IMap
    Set pMap = pMxDocument.FocusMap

    Dim pLayers As IEnumLayer
    Set pLayers = pMap.Layers

    Dim pFeatureLayer As IGeoFeatureLayer
    Set pFeatureLayer = pMap.Layer(0) ‘1st layer in TOC

    Dim i As Integer

    Dim pLegendInfo As ILegendInfo
    Dim pLegendGroup As ILegendGroup
    Dim strValue As String
    Dim strText As String

    Dim pUVRend As IUniqueValueRenderer
    Set pUVRend = pFeatureLayer.Renderer

    For i = 0 To pUVRend.ValueCount – 1
    varValue = pUVRend.Value(i)
    strValue = varValue
    ”Pass renderer value to a function which retrieves a string to use for the description
    strText = GetString(strValue)
    pUVRend.Description(varValue) = strText

    Next i

    pMxDocument.UpdateContents

    End Sub

    Function GetString(strVal As String) As String

    ‘Requires reference to DAO
    ‘Probably not the best idea to open and close the database in this function as this is repeated every
    ‘time it’s called by the main sub!

    Dim strPath As String

    Dim db As DAO.Database
    Dim strSQl As String
    Dim rs As DAO.RecordSet

    Dim strPlotLabel As String
    Dim i As Integer

    strDB = “this string should be the full path to the mdb file – including the file extension”

    Set db = OpenDatabase(strDB, False, False)

    strSQl = “SELECT * FROM tblLookup WHERE [LEX_RCS] = ‘” & strVal & ” ‘”
    Set rs = db.OpenRecordset(strSQl, , dbOpenForwardOnly)

    If Not rs.EOF Then
    GetString = rs.Fields(“LEX_D”).Value
    Else
    GetString = “XXX”
    End If

    TidyUpAndExit:

    rs.Close
    Set rs = Nothing

    db.Close
    Set db = Nothing

    End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s