Select to view content in your preferred language

Layer's symbology polygon info stuck in "all other values" with arcpy

652
5
Jump to solution
04-26-2023 01:46 PM
nsidaniel
New Contributor III

I have some arcpy python code that successfully writes the symbology of a layer but the actual polygons only show up as "<all other values>". Any ideas on how to correct this?

The fields data are domain values, I'm not sure if that effects anything.

nsidaniel_0-1682540843628.png

 

Here's the code:

import arcpy, sys, os
print(TWP)

aprx = arcpy.mp.ArcGISProject("Current")
m = aprx.listMaps("Map")[0]
l = m.listLayers(TWP + "_RIGHTS")[0]
sym = l.symbology
    
sym.updateRenderer('UniqueValueRenderer')
sym.renderer.fields = ['RightsType']

for grp in sym.renderer.groups:
    for itm in grp.items:
        label = itm.label

        if itm.label == "Choose":
            itm.symbol.color = {"RGB": [0, 0, 0, 50]}      
            itm.symbol.outlineColor = {"RGB": [255, 255, 255, 100]}
            itm.symbol.outlineWidth = 0.75
            itm.label = str(label)

        elif itm.label == "Easement":
            itm.symbol.color = {"RGB": [0, 112, 255, 50]}      
            itm.symbol.outlineColor = {"RGB": [255, 255, 255, 100]}
            itm.symbol.outlineWidth = 0.75  
            itm.label = str(label)

        elif itm.label == "Fee":
            itm.symbol.color = {"RGB": [56, 168, 0, 50]}
            itm.symbol.outlineColor = {"RGB": [255, 255, 255, 100]}
            itm.symbol.outlineWidth = 0.75
            itm.label = str(label)

        elif itm.label == "License":
            itm.symbol.color = {"RGB": [255, 0, 0, 50]}
            itm.symbol.outlineColor = {"RGB": [255, 255, 255, 100]}
            itm.symbol.outlineWidth = 0.75
            itm.label = str(label)

        print(label)    
    l.symbology = sym

aprx.save() 
print("Completed"+" "+time.strftime("%x" +" "+ "(%a)" +" "+ "at"+" "+"%I:%M"))

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
nsidaniel
New Contributor III

I found that arcpy.da.UpdateCursor causes the polygons' information to be stuck in <all other values> and thus unable to display the symbology. @Anonymous User identified that this is bug.

View solution in original post

0 Kudos
5 Replies
by Anonymous User
Not applicable

If the itm.label is already a string label, setting it again is somewhat redundant and could be causing the problem with groupings there.  What does this give you, with omitting the assignment?

import arcpy, sys, os

print(TWP)

aprx = arcpy.mp.ArcGISProject("Current")
m = aprx.listMaps("Map")[0]
l = m.listLayers(TWP + "_RIGHTS")[0]
sym = l.symbology

sym.updateRenderer('UniqueValueRenderer')
sym.renderer.fields = ['RightsType']

grpColors = { 'Choose' : {"RGB": [0, 0, 0, 50]},
              'Easement' : {"RGB": [0, 112, 255, 50]},
              'Fee' : {"RGB": [56, 168, 0, 50]},
              'License': {"RGB": [255, 0, 0, 50]}
              }

for grp in sym.renderer.groups:
    for itm in grp.items:
        itm.symbol.color = grpColors.get(itm.label, {"RGB": [255, 255, 255, 50]})
        itm.symbol.outlineColor = {"RGB": [255, 255, 255, 100]}
        itm.symbol.outlineWidth = 0.75

        print(itm.label)
    l.symbology = sym

aprx.save()
print("Completed" + " " + time.strftime("%x" + " " + "(%a)" + " " + "at" + " " + "%I:%M"))

 

nsidaniel
New Contributor III

@Anonymous UserThat's some really elegant code.

Unfortunately, all of the info remains as "<all other values>"! I'm beginning to suspect that the issue is more basic. Since TWP + "_RIGHTS" is a File Geodatabase Feature Class, it's simply is not possible to apply symbology unless I convert it to a SHP file first which of course loses the domain drop-down fields.

0 Kudos
by Anonymous User
Not applicable

That is odd, since it worked on a test dataset for but my value and label was both 0,1,2, though so it matched. It being in a fgdb shouldn't matter.  I wonder if it's grouping the value.  In your picture, the value is numbers, but the label is a string... what if you use the itm.values[0][0] instead?

grpColors = {'0': {'color': {"RGB": [0, 0, 0, 50]}, 'label': 'Choose'},
             '1': {'color': {"RGB": [0, 112, 255, 50]}, 'label': 'Easement'},
             '2': {'color': {"RGB": [56, 168, 0, 50]}, 'label': 'Fee'},
             '3': {'color': {"RGB": [255, 0, 0, 50]}, 'label': 'License'},
             }

for grp in sym.renderer.groups:
    for itm in grp.items:
        d = grpColors.get(itm.values[0][0], {'color': {"RGB": [255, 255, 255, 50]}, 'label': 'Not Matched'})

        itm.symbol.color = d['color']
        itm.symbol.outlineColor = {"RGB": [255, 255, 255, 100]}
        itm.symbol.outlineWidth = 0.75
        itm.label = d['label']
        print(itm.label)

l.symbology = sym

 

nsidaniel
New Contributor III

It still didn't work @Anonymous User! Did your test layer have domains?

0 Kudos
nsidaniel
New Contributor III

I found that arcpy.da.UpdateCursor causes the polygons' information to be stuck in <all other values> and thus unable to display the symbology. @Anonymous User identified that this is bug.

0 Kudos