<?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: Create new Feature Classes from attribute selection loop in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-new-feature-classes-from-attribute/m-p/709732#M55019</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you ! Your code worked! Below is my final code with the kernel denisty estimation replacing point density. I still do not understand the for loop though. You create a variable with the name specified by the year list and then an empty layer in the workspace with that name. You are then selecting by attributes in that new layer, but how are the attributes associated with that layer? I thought this was a new empty layer from the arcpy.MakeFeatureLayer_management function? I don't see how the attribute table from the YearFC variable is associated with the new layer. Can you explain?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 25 Jun 2012 21:06:39 GMT</pubDate>
    <dc:creator>deleted-user-IR249IovB3CN</dc:creator>
    <dc:date>2012-06-25T21:06:39Z</dc:date>
    <item>
      <title>Create new Feature Classes from attribute selection loop</title>
      <link>https://community.esri.com/t5/python-questions/create-new-feature-classes-from-attribute/m-p/709730#M55017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to loop through year values in an attribute field of a point feature class and create new point feature classes of all features for each year. For example an FC for 2004, an FC for 2005, and FC for 2006, etc.. The attribute field "yr" is the numeric integer field containing the year values. I want to select all points with "yr" = 2004 and create a new feature class 2004_ELB and so on for the remaining years. My code is below. My SelectLayerByAttribute_management query seems to be incorrect. Beyond that I'm not clear if my loop logic is correct either. Any help is greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# set workspace environment&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env = arcpy.env.workspace = "C:/Files/GIS/Projects/Hypoxia/Shrimp_Hypoxia/AnalysisData.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Set OverWrite if files already exist&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Make a layer from the feature class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FC = arcpy.MakeFeatureLayer_management("Full_Dataset_Albers", "FC")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Create a list of years to iterate through to enable selection of each year&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;yrlist = [2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print yrlist&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Initiate Search Cursor to use in loop of attribute values&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rows = arcpy.SearchCursor(FC)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldName = "yr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row.getValue(fieldName)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for year in yrlist:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (FC, "NEW_SELECTION", "yr" = yrlist)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(YearFC, str(year) + "_ELB")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2012 18:49:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-new-feature-classes-from-attribute/m-p/709730#M55017</guid>
      <dc:creator>deleted-user-IR249IovB3CN</dc:creator>
      <dc:date>2012-06-22T18:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create new Feature Classes from attribute selection loop</title>
      <link>https://community.esri.com/t5/python-questions/create-new-feature-classes-from-attribute/m-p/709731#M55018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is your code simplified - at the end I'm calling Copy Features tool. In your case you need to Point Density tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

# set workspace environment
arcpy.env.workspace = r"C:\data\my.gdb"

#Set OverWrite if files already exist
arcpy.env.overwriteOutput = True

#Create a list of years to iterate through to enable selection of each year
yrlist = [2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011]

YearFC = "myfc"

for year in yrlist:

&amp;nbsp;&amp;nbsp;&amp;nbsp; Year_layer = str(year) + "_ELB"

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(YearFC, Year_layer)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (Year_layer, "NEW_SELECTION", "\"Yr\" = %d" % (year))

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(Year_layer, "fc_" + str(year))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:25:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-new-feature-classes-from-attribute/m-p/709731#M55018</guid>
      <dc:creator>NobbirAhmed</dc:creator>
      <dc:date>2021-12-12T06:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create new Feature Classes from attribute selection loop</title>
      <link>https://community.esri.com/t5/python-questions/create-new-feature-classes-from-attribute/m-p/709732#M55019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you ! Your code worked! Below is my final code with the kernel denisty estimation replacing point density. I still do not understand the for loop though. You create a variable with the name specified by the year list and then an empty layer in the workspace with that name. You are then selecting by attributes in that new layer, but how are the attributes associated with that layer? I thought this was a new empty layer from the arcpy.MakeFeatureLayer_management function? I don't see how the attribute table from the YearFC variable is associated with the new layer. Can you explain?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Jun 2012 21:06:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-new-feature-classes-from-attribute/m-p/709732#M55019</guid>
      <dc:creator>deleted-user-IR249IovB3CN</dc:creator>
      <dc:date>2012-06-25T21:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create new Feature Classes from attribute selection loop</title>
      <link>https://community.esri.com/t5/python-questions/create-new-feature-classes-from-attribute/m-p/709733#M55020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The Make Feature Layer creates a layer, say named "2004_ELB", from the source feature class YearFC. This layer actually is same as the YearFC but lives in memory - it has (in fact, refers to) same number of records and fields. It's just an image of the feature class. So, the Make Feature Layer is not creating any "empty layer" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then you make selection from that layer and so on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note: if this solves your issue please mark the thread as "answered" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Jun 2012 21:40:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-new-feature-classes-from-attribute/m-p/709733#M55020</guid>
      <dc:creator>NobbirAhmed</dc:creator>
      <dc:date>2012-06-25T21:40:14Z</dc:date>
    </item>
  </channel>
</rss>

