5

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...

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

1 Answer 1

7

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")
2
  • I added MakeFeatureLayer on every shapefile, but the same error was raised.
    – Mingshu
    Sep 10, 2013 at 19:43
  • I added code. It should be enough to get you started
    – KHibma
    Sep 10, 2013 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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