ERROR 000732 when converting kml to layer with python

01-26-2023 11:11 PM
by Anonymous User
Not applicable

Hi All,

I am relatively new to python. I am trying to convert km* files into layers in a GDB but I am getting the following error: ERROR 000732: Input KML File: Dataset 413 REDD Project.kml does not exist or is not supported
Failed to execute (KMLToLayer).

Any comments would be highly appreciated 



import arcpy
import os
# Set workspace (where all the KMLs are)
arcpy.env.workspace = r'H:\My Drive\map of carbon projects\kmz'

# Set local variables and location for the consolidated file geodatabase
outLocation = r'H:\My Drive\map of carbon projects\shp'
MasterGDB = 'AllKMLLayers.gdb'

MasterGDBLocation = os.path.join(outLocation, MasterGDB)

# Create the master FileGeodatabase
arcpy.CreateFileGDB_management(outLocation, MasterGDB)

# Convert all KMZ and KML files found in the current workspace
for kmz in arcpy.ListFiles('*.KM*'):
print("CONVERTING: {0}".format(os.path.join(arcpy.env.workspace, kmz)))
arcpy.KMLToLayer_conversion(kmz, outLocation)

# Change the workspace to fGDB location
arcpy.env.workspace = outLocation

# Loop through all the FileGeodatabases within the workspace
wks = arcpy.ListWorkspaces('*', 'FileGDB')
# Skip the Master GDB

for fgdb in wks:

# Change the workspace to the current FileGeodatabase
arcpy.env.workspace = fgdb

# For every Featureclass inside, copy it to the Master and use the name from the original fGDB
featureClasses = arcpy.ListFeatureClasses('*', '', 'Placemarks')
for fc in featureClasses:
print("COPYING: {0} FROM: {1}".format(fc, fgdb))
fcCopy = os.path.join(fgdb, 'Placemarks', fc)
arcpy.FeatureClassToFeatureClass_conversion(fcCopy, MasterGDBLocation, fgdb[fgdb.rfind(os.sep) + 1:-4])
Tags (1)
0 Kudos
2 Replies
Occasional Contributor III

Could it be a problem that the kml name starts with a number or the spaces in your pathnames?

0 Kudos
MVP Esteemed Contributor

from Solved: Python standalone script using ArcGIS Pro license - Esri Community

for kmz in arcpy.ListFiles("*.km*"):
    print("CONVERTING: {0}".format(os.path.join(arcpy.env.workspace, kmz)))

    kmzFile = os.path.join(arcpy.env.workspace, kmz)
    arcpy.KMLToLayer_conversion(kmzFile, out_location)

You just did the path joining for the print statement but didn't carry it over to the KMLToLayer line

... sort of retired...
0 Kudos