Advanced Python Labels are not appearing in Map Service.

689
3
09-15-2017 06:34 AM
dineshpatil2
New Contributor III

Hello, 

I am trying to assign labels to feature layer using advance python labelling.

The label are fetching from feature layer related table using following python script logic, which is given at ESRI Tech Support How To: Label a related table 

def FindLabel ([keyField], [FirstLabel]):
    import arcpy

    key1 = [keyField] # Key field in feature class
    key2 = "ID"   # Key field in related table
    L = [FirstLabel] # Label field in feature class
    L2 = "Label2"   # Label field in related table
    myDataTable = r"<path-to-related-table>"   # Path to related table
    
    cur = arcpy.da.SearchCursor(myDataTable, [key2, L2])
    for row in cur:
        if str(key1) == str(row[0]): 
            L = L + " " + str(row[1])
    return L

The label are appearing in 'ArcMap'  window.  While publishing the feature layer as a Map Service; In the publishing preview window the labels do appear, but not in the finished service. 

0 Kudos
3 Replies
JonathanQuinn
Esri Frequent Contributor

I would focus on the following line:

 myDataTable = r"<path-to-related-table>"   # Path to related table

Does the ArcGIS Server account have access to the related table?  There's a chance that the rendering logic by a map service can't reach out to another table to draw labels.  Are there any logs when the logging level is set to Debug or Verbose?

MichaelVolz
Esteemed Contributor

Is the related table in the same geodatabase as the feature layer it is associated with?  If it is not then the labels will not work, at least that how it was for me so I had to ensure the related table was in the same geodatabase.

DmitryShatilov
New Contributor

Hi guys,

I have the same issue - I can see the label in ArcMap or in the preview before I publish it as a web service, but cannot see them in ArcGIS Online. I suspect there might be a problem with the path I use in the label expression.

It looks something like this: "Database Connections\TEST.sde\Related_Table". Am I missing something?

Also, I have created a brand new geodatabe, where I put a feature class and a related table I want to get the labels from. In this case my paths looks like that - "C:\Test.gdb\Related_Table". Again, it works fine in ArcMap, but there are no labels after I have published it as a web service?

Please, help!

Thanks heaps in advance!

0 Kudos