Custom Symbology in Python

806
5
07-21-2020 07:57 AM
AdamBakiera
Occasional Contributor

Good morning,

I have a client that needs individual KMZ layers exported fairly regularly. They also need the layers to have a custom symbology that needs to stay consistent. Most of the layers use unique values for their symbology. The layers are housed in an enterprise .sde. I was hoping to have everything in one .mxd and set up a script to utilize the 'map to kml' tool. Unfortunately, they won't accept a file that includes all of the layers Does anyone know of a way to accomplish this using python? 

0 Kudos
5 Replies
DavidPike
MVP Frequent Contributor

If I understand correctly you're looking for a script to look at all the layers in the MXD then export them as individual KMLs with appropriate names?

0 Kudos
AdamBakiera
Occasional Contributor

It would be great if I could get it to work with the .mxd because that would eliminate the need to have to write code for custom symbology. 

0 Kudos
DavidPike
MVP Frequent Contributor

Do you have any experience with python/arcpy? Or do you just want it written for you? It's pretty simple either way.

0 Kudos
AdamBakiera
Occasional Contributor

I have some experience but I'm far from expert level. Now that I've thought of this a little more, I think maybe I was overthinking. If I can set the workspace to be the .mxd and just have several 'layer to kml' lines, that should work, right?

0 Kudos
DavidPike
MVP Frequent Contributor

Sort of,  turn your mxd into a MapDcoument object then use ListLayers to get the layer objects in the MXD.  You should then be able to pass that list layer Object into the layer to KML tool,

something like below but I've probably mistyped something

import arcpy, os

mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")

df = arcpy.mapping.ListDataFrames(mxd, "")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
    workspace = a folderpath to write kmls to
    outKML = create a path with something like os.path.join(workspace, lyr.name)
    arcpy.LayerToKML_conversion(layer, outKML)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos