I was trying to convert all the shp in a folder into kml.

featureclasses = arcpy.ListFeatureClasses()

for fc in featureclasses:

 # Set Local Variables

 composite = 'COMPOSITE'

 pixels = 1024

 dpi = 96

 clamped = 'CLAMPED_TO_GROUND'

 scale = 1

 outKML = fc[:-4] + ".kmz"

 arcpy.LayerToKML_conversion(fc,outKML, scale, composite,'', pixels, dpi, clamped)

It always says Failed to execute. Parameters are not valid. ERROR 000732: Layer: Dataset ZZZ.shp does not exist or is not supported Failed to execute (LayerToKML).

But I can manually do it within ArcMap 10.1 Desktop...

  • Welcome to GIS SE, are you defining an workspace directory before your loop?
    – artwork21
    Sep 10 '13 at 16:23
  • Yes, I did. But I looks that is not the problem
    – Mingshu
    Sep 10 '13 at 19:50

This is because the Layer to KML tool takes either LAYERS (feature layers in a map for example), or LAYER FILES (.lyr files on disk pointing at featureclasses).

If you want to run this as a script outside of ArcMap you'll have to run MakeFeatureLayer on every shapefile, turning them into a layer first and pass that onto Layer to KML.

This is starter code...you'll have to modify it to make unique names. As-is it'll overwrite each KMZ it outputs.

featureclasses = arcpy.ListFeatureClasses()
for fc in featureclasses:
    arcpy.MakeFeatureLayer_management(fc, "name1")
    arcpy.LayerToKML_conversion("name1", r"c:\temp\foo1.kmz")
  • I added MakeFeatureLayer on every shapefile, but the same error was raised.
    – Mingshu
    Sep 10 '13 at 19:43
  • I added code. It should be enough to get you started
    – KHibma
    Sep 10 '13 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.