AnsweredAssumed Answered

Kml to Shp

Question asked by CCweedcontrol on Oct 25, 2018
Latest reply on Oct 25, 2018 by CCweedcontrol

I have the following code to convert KML to Shapefiels but i am getting error on line 26 i am not sure why?

line 26, in <module>

ValueError: list.remove(x): x not in list


import arcpy, os

# Set workspace (where all the KMLs are)
arcpy.env.workspace="D:\GIS Folder\IDTrialsRoads"

# Set local variables and location for the consolidated file geodatabase
outLocation = "D:\GIS Folder\IDTrialsRoads"
MasterGDB = 'TrailsRoads.mdb'
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: " + 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: " + fc + " FROM: " + fgdb   
    fcCopy = fgdb + os.sep + 'Placemarks' + os.sep + fc   
    arcpy.FeatureClassToFeatureClass_conversion(fcCopy, MasterGDBLocation, fgdb[fgdb.rfind(os.sep)+1:-4] + "_" + fc)