cjl5108

Python to convert .mxd to kml/kmz

Discussion created by cjl5108 on Dec 22, 2010
Hey all:

Fairly new to the python game, but I have a problem with converting a .mxd file created in ArcMAp to a KML file (.kmz) so that someone using a platform such as GoogleEarth can see the layers. For testing purposes i am working in the "temp" space so it doesnt try to convert all of my files. The problem I am having is that Python completes the operation w/o any errors, and then the knz file is 1kb when the original file is over 2k KB, and nothing shows up in GoogleEarth. If anyone has any insight it would be greatly appreciated, and I'm sorry if i don't understand what you are trying to tell me at first (like I said I am fairly new!)

Here's my code:

import arcpy
from arcpy import env
arcpy.CheckOutExtension("3D")
env.workspace = "C:/temp"

try:
# Use the ListFiles method to identify all layer files in workspace
if len(arcpy.ListFiles('*.mxd')) > 0:
for mxd in arcpy.ListFiles('*.mxd'):
# Set Local Variables
dataFrame = 'Layers'
composite = 'NO_COMPOSITE'
vector = 'VECTOR_TO_VECTOR'
pixels = 2048
dpi = 192
for scale in range(10000, 30001, 10000):
outKML = mxd[:-4]+'.kmz'
arcpy.MapToKML_conversion(mxd, dataFrame, outKML, scale,
composite, vector, '', pixels, dpi)
else:
arcpy.AddMessage('There are no map documents (*.mxd) in '+env.workspace)

except Exception as e:
print e.message

Outcomes