AnsweredAssumed Answered

Split records into multiple Feature Datasets

Question asked by johnmdye on May 28, 2013
Latest reply on May 28, 2013 by rzufelt
So, now I'm trying to split records into multiple feature datasets, based on the record's unique value. The end goal is to have a seperate feature dataset for each unique record. I'm getting some errors when trying to dynamically create the feature dataset though. I figured the easiest way to accomplish this would be through two seperate loops, one to create the Feature Datasets based on the uniqueVal and another to actually perform the split.

workspace = arcpy.env.workspace = r"C:\Users\jdk588\Documents\New File Geodatabase.gdb"
fc = r"C:\Users\jdk588\Documents\New File Geodatabase.gdb\Selected_CBSAs"
uniqueSet = set([r[0] for r in arcpy.da.SearchCursor (fc, ["ID"])])
for uniqueVal in uniqueSet:
     print "Creating Feature Dataset for CBSA " + uniqueVal + "..."
     arcpy.CreateFeatureDataset_management(workspace, "CBSA_" + str(uniqueVal))
     print "Successfully created CBSA " + str(uniqueVal) + " Feature Dataset."

for uniqueVal in uniqueSet:
     featureDataset = arcpy.ListDatasets("*" + str(uniqueVal), "Feature")
     workspace = arcpy.env.workspace = featureDataset
     print "Splitting CBSA " + str(uniqueVal) + "..."
     arcpy.Select_analysis(fc, "CBSA_" + str(uniqueVal) + "_bdy", "ID = " + str(uniqueVal))
     print "Success."

Creation of the featuredatasets works fine and it creates them all. However in the second loop, I'm trying to load each feature into its own feature dataset using the Select_analysis tool, which means I need to set the workspace to the appropriate feature dataset with each iteration of the loop. I'm not understanding why it can't access the workspace.

Runtime error
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\", line 529, in set_
self[env] = val
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\", line 581, in __setitem__
ret_ = setattr(self._gp, item, value)
RuntimeError: Object: Error in accessing environment <workspace>