2

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')
Taras
35.7k5 gold badges77 silver badges151 bronze badges
asked Jul 9, 2021 at 19:34

1 Answer 1

4

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.

answered Jul 10, 2021 at 2:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.