label related table - in one staked label

10380
15
Jump to solution
12-06-2012 12:57 PM
by Anonymous User
Not applicable
Original User: alnesbit

Hello all,

I am hoping someone who knows python can figure this out. I have a similar posting here http://forums.arcgis.com/threads/68883-Related-table-labels . There was an old arcscripts that worked at 9.3 here http://arcscripts.esri.com/details.asp?dbid=12298

I have been able to create a new feature class from using the Make Query Table tool that has all of my related values for my points in one feature class. What I really need know is a way to create one balloon label for each point that is a staked label of all of the related table values. Can I do this with python code or a label expression somehow? In some cases I have 6 or more balloon labels for each of my points and they are overlapping and hard to read.

I am attaching a screen shot of my map book as it is labeled with the many labels for each point. Then I am showing the table that the labels are coming from - showing the many assemblies for each pole.

The last thing I will add is an idea of python labeling code. This python label expression doesn't work but I thought maybe someone out there who knew code better than me could get it to work.

def FindLabel ( [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT], [POLE_PRIKEY]  ):   if long( [POLE_PRIKEY] ) = long( [POLE_PRIKEY] ):      return [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT] + '\n' + [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT] + '\n'  + [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT]    else:      return [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT] 


I appreciate any help!
Thank you,
0 Kudos
15 Replies
TimSexton1
Occasional Contributor

I know this is old, but I came across this link that helped me label from a related table with an advanced expression.

0 Kudos
by Anonymous User
Not applicable

Tim,

I tried the code you linked to but it doesn't work for me. Any idea why?

Function FindLabel ( [UniqueID] )

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

strWhereClause = chr(34) & "UniqueID" & chr(34) & " = '" & [UniqueID] & "'"

strpTable = C:\Users\abohn\Documents\RALLS_TEST.gdb\FIBER_ASSEMBLY_UNITS_AEG_gdb

Set prows = gp.searchcursor(strpTable,strWhereClause)

Set prow = prows.next

Do until prow is nothing

strLabel = prow.ASSEBMLY_UNIT

FindLabel = FindLabel & strLabel & vbnewline

Set prow = prows.next

Loop

End Function

0 Kudos
TimSexton1
Occasional Contributor

The related table has to be added to the TOC.  Make sure you are setting your strpTable variable to the actual table name (without the GDB path).  I could not get it to work the way your are trying by using the full file path to the table.  Also make sure the whereclause is querying on the correct foreign key (in your code it looks like your primary key and foreign key are named the same - which may be the case, just verify).  Also make sure the "Advanced - VBscript" expression is used.

Sample code:

Function FindLabel ( [GlobalID] )

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

strWhereClause = "OperationGUID = '" & [GlobalID] & "'"

strpTable = "RelatedTableNameHere"

Set prows = gp.searchcursor(strpTable,strWhereClause)

Set prow = prows.next

Do until prow is nothing

strLabel = prow.Description

FindLabel = FindLabel & strLabel & vbnewline

Set prow = prows.next

Loop

End Function

Hope this helps!

by Anonymous User
Not applicable

Awesome! It works!! I can't believe it! So cool.

I didn't have quotes around my "PathToRelatedTable" so that works now and I don't have to have the table in my TOC then. But in production I actually want to use an SDE table so I will have that in my TOC so I will just use the "RelatedTableName" like you mentioned. Thank you!

I have a further question though. In my code below I added a Quantity field to my label. But when the Quantity is 1 I don't want it to put the "(1)" there. I just want the "(2)" quantity label when the Quantity > 1. Do you know how to add in this logic?

Code:

Function FindLabel ( [UniqueID] )

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

strWhereClause = chr(34) & "UniqueID" & chr(34) & " = '" & [UniqueID] & "'"

strpTable = "FIBER_ASSEMBLY_UNITS"

Set prows = gp.searchcursor(strpTable,strWhereClause)

Set prow = prows.next

Do until prow is nothing

strLabel = prow.ASSEMBLY_UNIT & " (" & prow.Quantity & ")"

FindLabel = FindLabel & strLabel & vbnewline

Set prow = prows.next

Loop

End Function

Thank you!

0 Kudos
TimSexton1
Occasional Contributor

Simply add an IF statement inside the loop prior to setting the FindLabel similar to below:

Do until prow is nothing

if prow.QuantityUsed <= 1 then

strLabel = prow.Description

else

strLabel = prow.Description & "(" & prow.QuantityUsed & ")"

end if

FindLabel = FindLabel & strLabel & vbnewline

Set prow = prows.next

Loop

by Anonymous User
Not applicable

Works perfect! Thank you!!