0

I am trying to extract all KMZ and kml files from a folder but it's giving me an error. File does exist in that folder.


    for kmz in arcpy.ListFiles('*.km*'):
        print ("CONVERTING: " + os.path.join(arcpy.env.workspace,kmz))
        arcpy.KMLToLayer_conversion(kmz, outLocation, "", "NO_GROUNDOVERLAY")

ERROR 000732: Input KML File: Dataset NMR102020202_XZCD7S_4850NW_ABCD5W_Poin.kmz does not exist or is not supported

I am not sure what's missing in this code.

3
  • What happens when you use the KML To Layer tool from its dialog to process just the one KMZ file that's giving you this error. If you get the same error then this is not an ArcPy issue, and you need to look closer at the tool's documentation.
    – PolyGeo
    Aug 12 '20 at 10:24
  • I can convert all the kmz files with no errors by using model builder, using the tool KML to layer and with arcpy if I specify one kmz file at a time.But when I try it in python using FOR LOOP, List files it gives me the error mentioned above.
    – MGoyal
    Aug 13 '20 at 14:22
  • Please use the edit button beneath your question to revise it with any requested clarifications.
    – PolyGeo
    Aug 13 '20 at 20:25
1

I figured it out. So this code is meant for Python version 2.7

If you are trying to use the code in Python version 3.6.8 then the code will be as follows

for kmz in arcpy.ListFiles('*.km*'):
    desc = arcpy.Describe(kmz)
    kml_input = desc.path+ "\"+ desc.baseName +'.'+ desc.extension
    print("Converting: " + kml_input)
    arcpy.KMLToLayer_conversion(kml_input, outLocation, "", "NO_GROUNDOVERLAY")
2
  • Essentially you're saying in ArcGIS Pro the tool doesn't respect the implied workspace environment and you need to pass in the full path to the file. Which. from your original post probably could have used os.path.join(arcpy.env.workspace,kmz) from your print statement
    – KHibma
    Aug 14 '20 at 14:14
  • That's correct.
    – MGoyal
    Aug 14 '20 at 19:57

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.