1

I have a problem that I'm not sure is functionality not built into arcpy or I'm just doing something wrong. I'm using arcpy.mapping.UpdateLayer() to apply symbology to a layer, but afterwards some elements of the symbology needs to be removed depending on the attributes of the value field. I've achived this programmatically, determining which symbology values need to be removed. I'm using something similar to the following code to remove undeeded values from the symbology.

lyr = arcpy.mapping.Layer(<layer name>)

a = lyr.symbology.classValues
b = lyr.symbology.classLabels

a --> [u'1', u'2', u'3', u'4', u'5']
b --> [u'Low', u'Moderate', u'High', u'Very High', u'Extreme']

a.remove('5')
b.remove('Extreme')

a --> [u'1', u'2', u'3', u'4']
b --> [u'Low', u'Moderate', u'High', u'Very High']

lyr.symbology.classValues = a
lyr.symbology.classLabels = b

arcpy.RefreshActiveView()

The method seems to work great. The problem is the colors set by the symbology change after the arcpy.RefreshActiveView(), which defeats the whole purpose of applying symbology in the first place. Is there a way to keep the colors the same after removing symbology values?

Thanks in advance!

1 Answer 1

2

The only way i know to remove symbology definitions whilst keeping all the required ones AND keeping the current symbology is manually in ArcMap. In case this is of help here are the instructions:

  1. Right click on layer in ArcMap and go to properties
  2. Select the symbology tab
  3. Right click the unwanted definition ('Extreme' in this case) and delete.

This leaves all other symbology in tact. The RefreshActiveView may, as part of its process, always refresh the symbology colours once you've editied the list of definitions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.