label polygons using arcpy

2932
3
01-13-2012 06:41 AM
JoshuaChan
New Contributor III
I'm trying to write a python script to automate some mapping. One of the tasks I haven't figured out is how to access a layer's label properties. I'd like to set the layer's label field. I want to make an expression (something like round([length_field],2) & " m"). And I want to set the font size and font color.

Does anyone know how to do this?

Someone sent me "UpdateLayer" as a potential solution. I tried it but it doesn't seem to work with labelling. I made up a dummy .lyr file and it successfully changed the symbology of my layer. But none of the label properties I set in the .lyr file seem to have been applied to my new layer.

(edit: my subject title is actually wrong. I'm trying to label a line feature... but I don't think that's going to change the methodology of how to do this... )
0 Kudos
3 Replies
DavidWatkins
Esri Contributor
With UpdateLayer, are you using False for the symbology_only parameter?  It defaults to True, so the label properties will only come across if you specify it as False.

For example:  arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, False)

Keep in mind this will bring all layers properties including symbology, font, font size, label expression, etc., so everything will need to be defined in the update .lyr file.

David
0 Kudos
RobertChappe1
New Contributor II

Setting False for me seems to overwrite EVERYTHING; the attributes, layer name, all of it.

It seems to have simple ran a Remove Layer and then an Add Layer rather than commuting the layer properties.

I simply want my layer to be 50% transparent and have the labels displayed with 15 point Y offset and Halo around the text.

Anyone experience this?

0 Kudos
JoshuaChan
New Contributor III
thanks! Yes, I've already set up everything I needed in the .lyr layerfile so setting it to "FALSE" worked.



With UpdateLayer, are you using False for the symbology_only parameter?  It defaults to True, so the label properties will only come across if you specify it as False.

For example:  arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, False)

Keep in mind this will bring all layers properties including symbology, font, font size, label expression, etc., so everything will need to be defined in the update .lyr file.

David
0 Kudos