<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Split records into multiple Feature Datasets in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239193#M18636</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Caleb!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just before you replied, I actually figured out that it was easier to just update the workspace directly with the 'uniqueVal' variable than to use the ListFeatureDatasets function. I agree with your thoughts on the ListFeatureDatasets function returning the value in brackets. os.path.join is probably a better way to go. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once I got the original code running, the first loop to 2 minutes to run and the second loop took 24 minutes to run for a total runtime of 26 minutes. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With that, I combined the functions into a single loop, hoping that would result in some level of improvement since it wouldn't need to loop through the dataset twice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for uniqueVal in uniqueSet:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Creating Feature Dataset for CBSA " + uniqueVal + "..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFeatureDataset_management(workspace, "CBSA_" + str(uniqueVal))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully created CBSA " + str(uniqueVal) + " Feature Dataset."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Resetting workspace to CBSA " + str(uniqueVal) + "'s Feature Dataset..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = r"C:\Users\jdk588\Documents\New File Geodatabase.gdb\CBSA_" + str(uniqueVal)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully reset Workspace."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Splitting CBSA " + str(uniqueVal) + " into Feature Dataset..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(fc, "CBSA_" + str(uniqueVal) + "_bdy", '"ID" = ' + "'" + str(uniqueVal) + "'")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully split CBSA " + str(uniqueVal) + " into Feature Dataset."

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even with the functions combined into a single loop, it still took 26 minutes to run the entire process from FD creation to splitting the uniqueVals into their respective FD. A little longer than I think it should take. I wonder if the os.path.join method you mention would result in any performance improvements. My instinct tells me it could, but I suspect it would be negligible since resetting the workspace only takes a second, if that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you or anyone else spot any areas I could revise to boost performance?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 12:02:31 GMT</pubDate>
    <dc:creator>JohnDye</dc:creator>
    <dc:date>2021-12-11T12:02:31Z</dc:date>
    <item>
      <title>Split records into multiple Feature Datasets</title>
      <link>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239191#M18634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
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:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Creating Feature Dataset for CBSA " + uniqueVal + "..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFeatureDataset_management(workspace, "CBSA_" + str(uniqueVal))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully created CBSA " + str(uniqueVal) + " Feature Dataset."

for uniqueVal in uniqueSet:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureDataset = arcpy.ListDatasets("*" + str(uniqueVal), "Feature")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace = arcpy.env.workspace = featureDataset
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Splitting CBSA " + str(uniqueVal) + "..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(fc, "CBSA_" + str(uniqueVal) + "_bdy", "ID = " + str(uniqueVal))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Success."
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "&amp;lt;string&amp;gt;", line 11, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 529, in set_&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; self[env] = val&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 581, in __setitem__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; ret_ = setattr(self._gp, item, value)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: Object: Error in accessing environment &amp;lt;workspace&amp;gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:13:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239191#M18634</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2021-12-12T16:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Split records into multiple Feature Datasets</title>
      <link>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239192#M18635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think it may fix it if you try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os
arcpy.env.workspace = 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:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Creating Feature Dataset for CBSA " + uniqueVal + "..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFeatureDataset_management(workspace, "CBSA_" + str(uniqueVal))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully created CBSA " + str(uniqueVal) + " Feature Dataset."

for uniqueVal in uniqueSet:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureDataset = arcpy.ListDatasets("*" + str(uniqueVal), "Feature")[0].encode('utf-8')&amp;nbsp; # remove unicoding
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = os.path.join(workspace, featureDataset)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Splitting CBSA " + str(uniqueVal) + "..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(fc, "CBSA_" + str(uniqueVal) + "_bdy", "ID = " + str(uniqueVal))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The way you had it before would be returning your one feature dataset, but it would be returned inside of a list in the square brackets. Using the list index of [0] should just return the name of that feature dataset by itself. I also used os.path.join() to join the original workspace with the featureDataset variable so that it had the full path.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:13:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239192#M18635</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T16:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Split records into multiple Feature Datasets</title>
      <link>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239193#M18636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Caleb!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just before you replied, I actually figured out that it was easier to just update the workspace directly with the 'uniqueVal' variable than to use the ListFeatureDatasets function. I agree with your thoughts on the ListFeatureDatasets function returning the value in brackets. os.path.join is probably a better way to go. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once I got the original code running, the first loop to 2 minutes to run and the second loop took 24 minutes to run for a total runtime of 26 minutes. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With that, I combined the functions into a single loop, hoping that would result in some level of improvement since it wouldn't need to loop through the dataset twice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for uniqueVal in uniqueSet:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Creating Feature Dataset for CBSA " + uniqueVal + "..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFeatureDataset_management(workspace, "CBSA_" + str(uniqueVal))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully created CBSA " + str(uniqueVal) + " Feature Dataset."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Resetting workspace to CBSA " + str(uniqueVal) + "'s Feature Dataset..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = r"C:\Users\jdk588\Documents\New File Geodatabase.gdb\CBSA_" + str(uniqueVal)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully reset Workspace."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Splitting CBSA " + str(uniqueVal) + " into Feature Dataset..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(fc, "CBSA_" + str(uniqueVal) + "_bdy", '"ID" = ' + "'" + str(uniqueVal) + "'")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully split CBSA " + str(uniqueVal) + " into Feature Dataset."

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even with the functions combined into a single loop, it still took 26 minutes to run the entire process from FD creation to splitting the uniqueVals into their respective FD. A little longer than I think it should take. I wonder if the os.path.join method you mention would result in any performance improvements. My instinct tells me it could, but I suspect it would be negligible since resetting the workspace only takes a second, if that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you or anyone else spot any areas I could revise to boost performance?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:02:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239193#M18636</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2021-12-11T12:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Split records into multiple Feature Datasets</title>
      <link>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239194#M18637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Can you or anyone else spot any areas I could revise to boost performance? ]&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is indeed more efficient to do it all in one loop. And yes, I have found that using the Select_analysis tool is usually very slow. In that case I usually will just create a temporary feature layer with a query then use CopyFeatures_management. Seems to be quite a bit faster. I would do a speed test on this to see if it works any quicker without the select tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for uniqueVal in uniqueSet:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Creating Feature Dataset for CBSA " + uniqueVal + "..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFeatureDataset_management(workspace, "CBSA_" + str(uniqueVal))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully created CBSA " + str(uniqueVal) + " Feature Dataset."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Resetting workspace to CBSA " + str(uniqueVal) + "'s Feature Dataset..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = r"C:\Users\jdk588\Documents\New File Geodatabase.gdb\CBSA_" + str(uniqueVal)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully reset Workspace."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Splitting CBSA " + str(uniqueVal) + " into Feature Dataset..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;query = '"ID" = ' + "'%s'" %uniqueVal
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmp = arcpy.MakeFeatureLayer_management(fc, 'tmp_lyr', query)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(tmp, 'CBSA_%s_bdy' %uniqueVal)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully split CBSA " + str(uniqueVal) + " into Feature Dataset."
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I test the speed of a lot of tools using something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
from datetime import datetime as d
startTime = d.now()

# Do all the stuff


print '(Elapsed time: %s)' %(str(d.now() - startTime)[:-3])
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:02:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239194#M18637</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T12:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Split records into multiple Feature Datasets</title>
      <link>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239195#M18638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;John,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try commenting out your print statements once you get it working correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have some scripts that take about a hour to run, will take 4 or more hours if I include the print statements.&amp;nbsp; Takes a lot more load/time than one would think.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 May 2013 16:25:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-records-into-multiple-feature-datasets/m-p/239195#M18638</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-05-28T16:25:38Z</dc:date>
    </item>
  </channel>
</rss>

