AnsweredAssumed Answered

Convert all .lyr inside .mxd into .kmz

Question asked by Romanceline on Jan 23, 2018

Hi everyone,

 

I'm looking for a way to convert all .lyr contained in a .mxd file into .kmz.

I wrote this script that is supposed to be simple but still, it doesn't seem to work.

The script is creating .kmz but these .kmz don't look like what they should. If I open them in ArcMap, I receive an error message saying "Warning, inconsistent extent". I can see some strange points though, but that seem aligned while they shouldn't be. If I open the kmz with Google Earth, it doesn't display anything, I just end up in the middle of the ocean...

 

   import arcpy
   arcpy.env.workspace = path
   mxd = arcpy.mapping.MapDocument(path)
   AllLayers=arcpy.mapping.ListLayers(mxd)
   for layer in AllLayers:
         outputkmz = layer.name[:-4]+".kmz"
         arcpy.LayerToKML_conversion(layer,outputkmz)

 

Additionnal information:

- If the mxd contains only one layer in the ToC, it's working. As soon as there are more than 1, it's not working anymore

- I don't think it's a problem of Coordinates System

- I tried to play with the output extent in LayerToKML but didn't change much

- When I convert the .lyr manually in ArcMap with the toolbox, it's working, so the problem shouldn't come from the .lyr

- I noticed that when I convert manually, it's also creating a metadata file while it doesn't when I run the script. I don't know if that might help?

 

I feel like I tried everything and I really don't get why the script isn't working properly.

Outcomes