<?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: Make feature layer &amp;gt; Select by attributes loop in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/make-feature-layer-amp-gt-select-by-attributes/m-p/432647#M34021</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm working on a similar problem and could use some guidance. I am trying to create new feature classes based on an attribute selection loop in python from an existing feature class. I can't figure out how to loop through the attribute values to select in a for loop? Perhaps create a list of unique values and then set up an if then statement?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;any guidance is much appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Jun 2012 15:45:11 GMT</pubDate>
    <dc:creator>deleted-user-IR249IovB3CN</dc:creator>
    <dc:date>2012-06-22T15:45:11Z</dc:date>
    <item>
      <title>Make feature layer &amp;gt; Select by attributes loop</title>
      <link>https://community.esri.com/t5/python-questions/make-feature-layer-amp-gt-select-by-attributes/m-p/432645#M34019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is my first adventure into Python scripting so excuse my ignorance. I am trying to loop through FC's in a GDB and select by an attribute then copy those feature classes into the GDB. Below is my script so far. Where my question lies is, in the 'SelectLayerByAttribute' process how do I specify the feature layer that was created in the previous step as the FC to do the selecting from? See where my question marks are below, that is where im unsure&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = r"\\Wmsmonfs01\gisprod\SDE Data Files\PERMITTING_ABA.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local Variables&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GDB = r"\\Wmsmonfs01\gisprod\SDE Data Files\PERMITTING_ABA.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get a list of all feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fcList = arcpy.ListFeatureClasses()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Loop through each feature class in the GDB&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for fc in fcList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; # Put in error trapping in case an error occurs when running tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; # Make a layer from the feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.MakeFeatureLayer_management(fc, fc + '_LYR')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; # Select features by attribute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.SelectLayerByAttribute_management("?????????", "NEW_SELECTION", "\"Source\" = 'GAI'")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; # Copy selected features to GDB &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.CopyFeatures_management("???????", GDB)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Apr 2012 13:06:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-feature-layer-amp-gt-select-by-attributes/m-p/432645#M34019</guid>
      <dc:creator>LouisEarly</dc:creator>
      <dc:date>2012-04-30T13:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Make feature layer &gt; Select by attributes loop</title>
      <link>https://community.esri.com/t5/python-questions/make-feature-layer-amp-gt-select-by-attributes/m-p/432646#M34020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Also I think copy features is the wrong process to use.&amp;nbsp; What I want is to export the selected features to a new FC and put it into the same GDB&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Apr 2012 16:20:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-feature-layer-amp-gt-select-by-attributes/m-p/432646#M34020</guid>
      <dc:creator>LouisEarly</dc:creator>
      <dc:date>2012-04-30T16:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Make feature layer &gt; Select by attributes loop</title>
      <link>https://community.esri.com/t5/python-questions/make-feature-layer-amp-gt-select-by-attributes/m-p/432647#M34021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm working on a similar problem and could use some guidance. I am trying to create new feature classes based on an attribute selection loop in python from an existing feature class. I can't figure out how to loop through the attribute values to select in a for loop? Perhaps create a list of unique values and then set up an if then statement?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;any guidance is much appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2012 15:45:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-feature-layer-amp-gt-select-by-attributes/m-p/432647#M34021</guid>
      <dc:creator>deleted-user-IR249IovB3CN</dc:creator>
      <dc:date>2012-06-22T15:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Make feature layer &gt; Select by attributes loop</title>
      <link>https://community.esri.com/t5/python-questions/make-feature-layer-amp-gt-select-by-attributes/m-p/432648#M34022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; This is my first adventure into Python scripting so excuse my ignorance. I am trying to loop through FC's in a GDB and select by an attribute then copy those feature classes into the GDB. Below is my script so far. Where my question lies is, in the 'SelectLayerByAttribute' process how do I specify the feature layer that was created in the previous step as the FC to do the selecting from? See where my question marks are below, that is where im unsure&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;import arcpy&amp;nbsp; &lt;BR /&gt;from arcpy import env&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;env.workspace = r"\\Wmsmonfs01\gisprod\SDE Data Files\PERMITTING_ABA.gdb"&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;# Local Variables&amp;nbsp; &lt;BR /&gt;GDB = r"\\Wmsmonfs01\gisprod\SDE Data Files\PERMITTING_ABA.gdb"&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;# Get a list of all feature classes&amp;nbsp; &lt;BR /&gt;fcList = arcpy.ListFeatureClasses()&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;# Loop through each feature class in the GDB&amp;nbsp; &lt;BR /&gt;for fc in fcList:&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt; # Put in error trapping in case an error occurs when running tool&amp;nbsp; &lt;BR /&gt; try:&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; # Make a layer from the feature classes&amp;nbsp; &lt;BR /&gt; arcpy.MakeFeatureLayer_management(fc, fc + '_LYR')&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; # Select features by attribute&amp;nbsp; &lt;BR /&gt; arcpy.SelectLayerByAttribute_management("&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;?????????&lt;/SPAN&gt;", "NEW_SELECTION", "\"Source\" = 'GAI'")&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; # Copy selected features to GDB&amp;nbsp;&amp;nbsp; &lt;BR /&gt; arcpy.CopyFeatures_management("&amp;nbsp; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;???????&lt;/SPAN&gt;", GDB)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You would have to do something like this&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Make a layer from the feature classes
fl = arcpy.MakeFeatureLayer_management(fc, fc + '_LYR')

# Select features by attribute
fl_sel = arcpy.SelectLayerByAttribute_management("fl", "NEW_SELECTION", "\"Source\" = 'GAI'")

# Copy selected features to GDB
arcpy.CopyFeatures_management("fl_sel", GDB) &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes Copy features may not work. Maybe try Feature Class To Feature Class&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:26:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-feature-layer-amp-gt-select-by-attributes/m-p/432648#M34022</guid>
      <dc:creator>SolomonPulapkura</dc:creator>
      <dc:date>2021-12-11T19:26:13Z</dc:date>
    </item>
  </channel>
</rss>

