I am converting an SHP to KML using ArcPy. How can I control the color display in the output KML?
For example, if my polyline SHP has a field called "Category" and my two options are "A" and "B," how can I create a KML (KMZ) such that all the polylines for "A" are red and "B" are blue?
I know from this cool color code webpage that the code for red (RGB=[20,0,250])
is "501400FA"
and blue (RGB =[240,10,20])
is "50F00A14"
I'm just not sure what field(s) to add to my SHP that will reflect this in the KMZ.
Using ArcMap 10.7
# simple ArcPy syntax for exporting SHP to KMZ
temp_layer = arcpy.MakeFeatureLayer_management('polylines.shp', "Project_Linework")
arcpy.LayerToKML_conversion(temp_layer, 'project_linework.kmz')
1 Answer 1
The Layer to KML tool takes whatever active symbology is applied to the layer and creates the KML with it. So if you have drawn your polylines by a category with A=red and B=blue using a Unique Value renderer in ArcMap, well, that's what your KML will look like (Red and Blue).
If you're working completely from Python/arcpy, outside ArcMap, you'll need to apply the symbology to the layer in another way. Using the Apply Symbology From Layer tool, you can take a .lyr
file (that you've previously created inside ArcMap) and run it, thus giving your layer "symbology". You'd run this tool immediately after your Make Feature Layer tool.