Kml to Shp

981
3
Jump to solution
10-25-2018 09:38 AM
CCWeedcontrol
Occasional Contributor III

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>

wks.remove(MasterGDBLocation)
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
wks.remove(MasterGDBLocation)

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)
0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Alum

Line 24 is referencing 'FileGDB', a file geodatabase; and MasterGDB is a personal geodatabase (.mdb).  I wonder if this could be your issue.

View solution in original post

3 Replies
RandyBurton
MVP Alum

Line 24 is referencing 'FileGDB', a file geodatabase; and MasterGDB is a personal geodatabase (.mdb).  I wonder if this could be your issue.

CCWeedcontrol
Occasional Contributor III

Doh, thanks.

0 Kudos
MichaelVolz
Esteemed Contributor

Your MasterGDB is a personal geodatabase and you are looping thru file geodatabases so you would not see the personal geodatabase in the list.