Label from a related table using Label Expression

4558
3
04-18-2016 08:16 AM
DamonOsbourne
New Contributor II

Looking for a label expression that will label from a relate.  It's a 1-to-many situation & desired result is to stack the labels from a field in the related table.  For example, it would be how a city would label tenants in one building, or like labeling residents (listed in a xls) on 1 apartment building.

Tags (2)
0 Kudos
3 Replies
WesMiller
Regular Contributor III
DamonOsbourne
New Contributor II

The dataset is relatively small so I don't need a dictionary.  Basically just looking for the python version of this VBScript that I found:

Function FindLabel ( [RelateFieldofLayer] )

Set gp = CreateObject("esriGeoprocessing.GPDispatch.1")

strWhereClause = chr(34) & "RelateFieldofTable" & chr(34) & " = '" & [RelateFieldofLayer] & "'"

strpTable = "PathToRelatedTable"

Set prows = gp.searchcursor(strpTable,strWhereClause)

Set prow = prows.next

Do until prow is nothing

strLabel = prow.LabelField

FindLabel = FindLabel & strLabel & vbnewline

Set prow = prows.next

Loop

End Function

0 Kudos
WesMiller
Regular Contributor III

I got the below to work but it's really slow.

def FindLabel ( [RelateFieldofTable] ):
    strWhereClause = '"' + "RelateFieldofTable" + '"' +  " = '" + [RelateFieldofTable] + "'"
    strpTable =  "PathToRelatedTable" 
    rows = arcpy.SearchCursor(strpTable,strWhereClause)
    strLabel = ''
    for row in rows:
        strLabel += '\n'+ row.FieldToLabel
    return [RelateFieldofTable] + strLabel