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

asked Sep 10, 2013 at 16:03
2
  • Welcome to GIS SE, are you defining an workspace directory before your loop? Commented Sep 10, 2013 at 16:23
  • Yes, I did. But I looks that is not the problem Commented 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")
answered Sep 10, 2013 at 16:29
2
  • I added MakeFeatureLayer on every shapefile, but the same error was raised. Commented Sep 10, 2013 at 19:43
  • I added code. It should be enough to get you started Commented Sep 10, 2013 at 20:47

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.