2

I'm currently making a map that uses custom colors for the layer symbology. It was requested that the labels for each class in the layer use the same color palette as the layer. Is there a way to automate this process other than doing it manually? Do I need to save the layer symbology as a style?

I am using ArcGIS for Desktop 10.4 to make this map.

2 Answers 2

2

I suggest using arcpy.mapping.UpdateLayer() function for that:

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Counties",df)[0]
source_layer = arcpy.mapping.Layer(r"C:\GIS\Temp\_Counties.lyr")

arcpy.mapping.UpdateLayer(df, lyr, source_layer,symbology_only=False)

You won't be able to update the color for the labels text with arcpy based on the colors of the layer features; this is not exposed with the coarse-grained arcpy API.

You will need:

  1. Update the symbology for the layer as needed.
  2. Update labels properties for this layer.
  3. Save a layer file (.lyr file) on the disk.
  4. Use Python to update the symbology and the labels.

Tips: use the Label Manager for specifying the properties for the label classes; it's just a nicer interface to work with comparing to the Layer Properties dialog box.

0

Paul, Here is a link to an add in that will let you import symbology for labels from another layer. You can manually set the label symbology for one of your layers, then use this to repeat the process.

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.