Select to view content in your preferred language

Change symbology of a shapefile or layer using Python

5209
3
03-18-2014 12:07 PM
JudyC
by
Deactivated User
I have a script that creates a layer and then converts it to a kmz. Is there a way to set the symbology of the layer file using Python in my script so that it shows up in the kml as the color I want?

For example, I have a layer file that displays building footprints and every time I use the layer to kml function it displays in Google Earth as a different color. I want it to display as red all the time.

I'm using ArcMap 10.2 and Python 2.7.3.

Thanks!
Tags (2)
0 Kudos
3 Replies
MattEiben
Deactivated User
It's odd that your symbology isn't carrying over.  I have a script that converts a series of layers (polygons, polylines, and points) to KMZ and seems to keep it's symbology fine.

One thins you could try is saving a copy or your preferred symbology somewhere on your system as a .lyr file and refer to that in your script to set symbology everytime the script runs.  Maybe something like this:

arcpy.ApplySymbologyFromLayer_management(your_layer, symbology_layer)

arcpy.SaveToLayerFile_management(your_layer, layer_to_be_coverted_to_kmz)

arcpy.LayerToKML_conversion(layer_to_be_coverted_to_kmz, output_kmz,1,"NO_COMPOSITE","",1024,96,"CLAMPED_TO_GROUND")
0 Kudos
JudyC
by
Deactivated User
The symbology is carrying over when I convert from layer to kml. However, the layer is created in the script using the make feature layer function, so I never get a chance to change the symbology in ArcMap. It appears that when the layer is created, it is just assigned a random color and that is what is shown in the kml. I'm curious if there is a script that will allow me to change the color.

Thank you for the suggestion of using the apply symbology from layer. I did create a layer file with the red color symbology and it worked. The problem with this is that the user would always have to have that one layer file for it to work, so if there is a way to get it directly in the script it would be much better.
0 Kudos
MattEiben
Deactivated User
I've had this exact problem before.  Unfortunately, through the arcpy.mapping module, there's currently no support for Python having access to the actual color properties for your symbology.

This has certainly limited me on several scripts as well.  To my knowledge, currently the best way is to have a .lyr file repository or bundle it with the script and use the Apply Symbology tool or the Update Layer tool.

Read here for the currently available symbology options:

arcpy mapping symbology options

Also, check out this forum post with a very similar issue

http://forums.arcgis.com/threads/90831-Programmatically-Set-Colors-for-Unique-Values-Symbology
0 Kudos