<?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: Select by attributes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730505#M56662</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I want to replicate something that I can do within ArcMap and model builder. I have a categorical raster with an attribute table consisting of 10 fields "Rowid", "Value", and "Count". I would like to use the SelectLayerByAttribute_Management tool using arcpy. My code so far is:&lt;BR /&gt;&lt;BR /&gt;# Import arcpy module&lt;BR /&gt;import arcpy&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# define the location of raster titled rstName &lt;BR /&gt;Rst = "C:/..../rstName"&lt;BR /&gt;&lt;BR /&gt;# Select Rowid = 0&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(Rst, "NEW_SELECTION", "\"Rowid\" = 0")&lt;BR /&gt;&lt;BR /&gt;The error msg I get is:&lt;BR /&gt;* File "C:\...\abc.py", line 16, in &amp;lt;module&amp;gt;&lt;BR /&gt;*** arcpy.SelectLayerByAttribute_management(Rst, "NEW_SELECTION", "\"Rowid\" = 0")&lt;BR /&gt;* File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4259, in SelectLayerByAttribute&lt;BR /&gt;*** raise e&lt;BR /&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000840: The value is not a Table View.&lt;BR /&gt;ERROR 000825: The value is not a layer or table view&lt;BR /&gt;ERROR 000840: The value is not a Mosaic Layer.&lt;BR /&gt;Failed to execute (SelectLayerByAttribute).&lt;BR /&gt;-------------------------&lt;BR /&gt;&lt;BR /&gt;Can some help me troubleshoot this issue?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SelectLayerByAttribute_management cannot take a raster directly as an input.&amp;nbsp; You need to create a layer for the raster using CreateLayer_Managment (I believe) and then use that as an input to the SelectLayerByAttribute_management tool.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 Dec 2011 16:47:39 GMT</pubDate>
    <dc:creator>RichardFairhurst</dc:creator>
    <dc:date>2011-12-20T16:47:39Z</dc:date>
    <item>
      <title>Select by attributes</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730504#M56661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to replicate something that I can do within ArcMap and model builder. I have a categorical raster with an attribute table consisting of 10 fields "Rowid", "Value", and "Count". I would like to use the SelectLayerByAttribute_Management tool using arcpy. My code so far is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# define the location of raster titled rstName &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Rst = "C:/..../rstName"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Select Rowid = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(Rst, "NEW_SELECTION", "\"Rowid\" = 0")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error msg I get is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;* File "C:\...\abc.py", line 16, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;*** arcpy.SelectLayerByAttribute_management(Rst, "NEW_SELECTION", "\"Rowid\" = 0")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;* File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4259, in SelectLayerByAttribute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;*** raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000840: The value is not a Table View.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000825: The value is not a layer or table view&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000840: The value is not a Mosaic Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByAttribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can some help me troubleshoot this issue?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 16:35:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730504#M56661</guid>
      <dc:creator>NareshPai</dc:creator>
      <dc:date>2011-12-20T16:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Select by attributes</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730505#M56662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I want to replicate something that I can do within ArcMap and model builder. I have a categorical raster with an attribute table consisting of 10 fields "Rowid", "Value", and "Count". I would like to use the SelectLayerByAttribute_Management tool using arcpy. My code so far is:&lt;BR /&gt;&lt;BR /&gt;# Import arcpy module&lt;BR /&gt;import arcpy&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# define the location of raster titled rstName &lt;BR /&gt;Rst = "C:/..../rstName"&lt;BR /&gt;&lt;BR /&gt;# Select Rowid = 0&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(Rst, "NEW_SELECTION", "\"Rowid\" = 0")&lt;BR /&gt;&lt;BR /&gt;The error msg I get is:&lt;BR /&gt;* File "C:\...\abc.py", line 16, in &amp;lt;module&amp;gt;&lt;BR /&gt;*** arcpy.SelectLayerByAttribute_management(Rst, "NEW_SELECTION", "\"Rowid\" = 0")&lt;BR /&gt;* File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4259, in SelectLayerByAttribute&lt;BR /&gt;*** raise e&lt;BR /&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000840: The value is not a Table View.&lt;BR /&gt;ERROR 000825: The value is not a layer or table view&lt;BR /&gt;ERROR 000840: The value is not a Mosaic Layer.&lt;BR /&gt;Failed to execute (SelectLayerByAttribute).&lt;BR /&gt;-------------------------&lt;BR /&gt;&lt;BR /&gt;Can some help me troubleshoot this issue?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SelectLayerByAttribute_management cannot take a raster directly as an input.&amp;nbsp; You need to create a layer for the raster using CreateLayer_Managment (I believe) and then use that as an input to the SelectLayerByAttribute_management tool.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 16:47:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730505#M56662</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2011-12-20T16:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Select by attributes</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730506#M56663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm doing something similar (not with rasters though) and I've found that I need to use MakeFeatureLayer_management and give it a name in order to use SelectLayerByAttribute_management or SelectLayerByLocation_management on my datasets. Good luck!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 17:04:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730506#M56663</guid>
      <dc:creator>RuthEmerick</dc:creator>
      <dc:date>2011-12-20T17:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Select by attributes</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730507#M56664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried your suggestion:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management works only for a feature layer (not raster).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My overall goal is to perform an &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Extract by Mask&lt;/SPAN&gt;&lt;SPAN&gt; operation in which the Mask is another raster (with specific attributes selected, sequentially, by an SQL query). Is there an alternative to perform this operation?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 17:29:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730507#M56664</guid>
      <dc:creator>NareshPai</dc:creator>
      <dc:date>2011-12-20T17:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Select by attributes</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730508#M56665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Could you use ExtractByAttributes(in_raster, where_clause) instead of SelectLayerByAttribute_management(in_layer_or_view, {selection_type}, {where_clause})?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 18:50:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730508#M56665</guid>
      <dc:creator>RuthEmerick</dc:creator>
      <dc:date>2011-12-20T18:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Select by attributes</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730509#M56666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Could you use ExtractByAttributes(in_raster, where_clause) instead of SelectLayerByAttribute_management(in_layer_or_view, {selection_type}, {where_clause})?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your reply.&amp;nbsp; My &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Mask Raster&lt;/SPAN&gt;&lt;SPAN&gt; has about 800 rows in its attribute column which I want to use sequentially for performing &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Extract by Mask&lt;/SPAN&gt;&lt;SPAN&gt; with &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;In Raster&lt;/SPAN&gt;&lt;SPAN&gt;. Your solution would work well except that it would create about 800 additional rasters.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 19:22:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730509#M56666</guid>
      <dc:creator>NareshPai</dc:creator>
      <dc:date>2011-12-20T19:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Select by attributes</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730510#M56667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Alright, I have found a solution that would work (for now):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for i in range(0,800):

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeRasterLayer_management(Mask_Rst,"MaskRst_lyr","Rowid = "+ str(i))

&amp;nbsp;&amp;nbsp;&amp;nbsp; outExtractByMask = ExtractByMask(InRst,"MaskRst_lyr")

&amp;nbsp;&amp;nbsp;&amp;nbsp; outExtractByMask.save(OutDir + "\\rst" + str(i))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:11:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes/m-p/730510#M56667</guid>
      <dc:creator>NareshPai</dc:creator>
      <dc:date>2021-12-12T07:11:16Z</dc:date>
    </item>
  </channel>
</rss>

