Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Failure to execute CreateFeatureClass

By: maphew on Sep 17th, 2012  |  syntax: Python  |  size: 2.67 KB  |  views: 39  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # http://gis.stackexchange.com/questions/33320
  2. # python-for-arcgis-10-problem-with-creating-multiple-featureclasses-in-geodatab
  3. import arcpy, os
  4.  
  5. #
  6. #Geodatabase = r"D:\GIS\STK\124_NDS\STK_124_NDS.gdb"
  7. Geodatabase = r"c:\temp\test.gdb"
  8. arcpy.env.overwriteOutput = True
  9.  
  10. def createTestHarness():
  11.     arcpy.CreateFileGDB_management('c:/temp', 'test.gdb')
  12.     for fd in ['one','two','three','four']:
  13.         arcpy.CreateFeatureDataset_management('c:/temp/test.gdb', fd)
  14.  
  15. def CreateFeatureclasses(workspace):
  16.     arcpy.env.workspace = Geodatabase
  17.     listDatasets = arcpy.ListDatasets("", "Feature")
  18.     print 'Active workspace:\t', arcpy.env.workspace
  19.     for dataset in listDatasets:
  20.         datasetPath = workspace + os.sep + dataset
  21.         arcpy.env.workspace = datasetPath
  22.         print 'Active workspace:\t', arcpy.env.workspace
  23.  
  24.         print "Dataset: " + dataset
  25.         #out_name = "BF_Stao_Bodenprofil_P_" + dataset[9:]
  26.         out_name = "BF_Stao_Bodenprofil_P_" + dataset
  27.         print "\tout_name", out_name
  28.         Bohrpunkt_fc = arcpy.CreateFeatureclass_management (datasetPath, out_name, "POINT")
  29.         fcList = arcpy.ListFeatureClasses()
  30.         for fc in fcList:
  31.             if fc[:10] == "Bohrpunkte":
  32.                 Punkteliste = []
  33.                 zeilen = arcpy.SearchCursor(fc)
  34.                 for zeile in zeilen:
  35.                     Bohrkreisgeometrie = zeile.getValue("Shape")
  36.                     Bohrpunkt = Bohrkreisgeometrie.trueCentroid
  37.                     Punkteliste.append(Bohrpunkt)
  38.                 del zeilen
  39.                 rows = arcpy.InsertCursor(Bohrpunkt_fc)
  40.                 for Punkt in Punkteliste:
  41.                     feature = rows.newRow()
  42.                     feature.shape = Punkt
  43.                     rows.insertRow(feature)
  44.                 del rows, Punkteliste
  45.                 print "Die Punkt-Geometrien fuer die Featureclass 'BF_Stao_Bodenprofil_P' wurden erstellt."
  46.                 Liegenschaftsnummer = dataset[1:8]
  47.                 arcpy.AddField_management (Bohrpunkt_fc, "Lgs_Nummer", "TEXT", "", "", 7)
  48.                 arcpy.AddField_management (Bohrpunkt_fc, "Profil_ID", "TEXT", "", "", 12)
  49.                 arcpy.AddField_management (Bohrpunkt_fc, "Profil_Nr_alt", "TEXT", "", "", 4)
  50.                 arcpy.AddField_management (Bohrpunkt_fc, "Profiltyp", "SHORT", 1)
  51.                 arcpy.AddField_management (Bohrpunkt_fc, "Standortseinheit", "TEXT")
  52.         del Bohrpunkt_fc
  53.     del listDatasets
  54.  
  55. try:
  56.     print '\ncreating test harness...'
  57.     createTestHarness()
  58.     print '\nabout to run CreateFeatureClasses...'
  59.     CreateFeatureclasses(Geodatabase)
  60. except:
  61.     print '\nException Messages:\n', arcpy.GetMessages()