<?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: Reading a Raster Attribute table in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/reading-a-raster-attribute-table/m-p/159053#M8886</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Xander.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My initial confusion about accessing the RAT table is functions like ListTables reveal no RATs. So its there but its not there sort of thing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But having all the raster parameters available with a Raster object is also quite handy, without having to go through a Describe object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, I see that if the permanent Raster is supplied to the da.SearchCursor, it reads the RAT fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Just a slight bit of inconsistency revealed here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Neil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Dec 2013 09:24:12 GMT</pubDate>
    <dc:creator>NeilAyres</dc:creator>
    <dc:date>2013-12-02T09:24:12Z</dc:date>
    <item>
      <title>Reading a Raster Attribute table</title>
      <link>https://community.esri.com/t5/data-management-questions/reading-a-raster-attribute-table/m-p/159051#M8884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Last week I answered a query about Null / Not Null counts in a raster.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As an aside there I asked about accessing the RAT from a raster.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After a bit of searching I have found the solution, its not quite what I expected.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Import the modules, navigate to my gdb containing the rasters, create a raster object "Ras1" and validate that it does indeed have a RAT.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; import sys, os, arcpy
&amp;gt;&amp;gt;&amp;gt; from arcpy import env
&amp;gt;&amp;gt;&amp;gt; env.workspace = "c:/Data/Python/NumPyArrays/ZimDem.gdb"
&amp;gt;&amp;gt;&amp;gt; arcpy.ListRasters()
[u'DemFill', u'FlowDir', u'DemFill_hs', u'Ras2', u'Ras3', u'Dem', u'Dem_hs', u'FlowD', u'Ras', u'FlowD_Temp', u'Dem_MaxUpstreamElevation', u'Temp', u'Dem_DD', u'CreateConsta1', u'XMapFinal', u'YMapFinal']
&amp;gt;&amp;gt;&amp;gt; arcpy.ListTables()
[]
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; Ras1 = arcpy.Raster("FlowD")
&amp;gt;&amp;gt;&amp;gt; Ras1.hasRAT
True
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try to use da.SearchCursor to list the RAT.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for r in arcpy.da.SearchCursor(Ras1, ["VALUE", "COUNT"]):
 print r[0], r[1]

Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;pyshell#11&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for r in arcpy.da.SearchCursor(Ras1, ["VALUE", "COUNT"]):
RuntimeError: 'in_table' is not a table or a featureclass
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;So the da.SearchCursor method, errors out because Ras1 is a raster object, not a table. Fair enough you might think.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, then try the "old" SearchCursor...&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
rows = arcpy.SearchCursor(Ras1, "", "", "VALUE; COUNT")
&amp;gt;&amp;gt;&amp;gt; for r in rows:
 v = r.getValue("VALUE")
 c = r.getValue("COUNT")
 print v, c

 
2 4254.0
4 4093.0
8 1572.0
16 3615.0
32 4112.0
64 9199.0
128 6344.0
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;So the old SearchCursor doesn't mind that the input is a raster object, and lists the Value; Count list no probs...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How odd is that?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Neil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:23:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/reading-a-raster-attribute-table/m-p/159051#M8884</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2021-12-11T08:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Raster Attribute table</title>
      <link>https://community.esri.com/t5/data-management-questions/reading-a-raster-attribute-table/m-p/159052#M8885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Neil,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I looked at your original post:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/97771-Calculate-percentage-of-NODATA-pixels-in-a-scene?p=347836#post347836" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/97771-Calculate-percentage-of-NODATA-pixels-in-a-scene?p=347836#post347836&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...and the fact that you can't access the RAT. This is strange. I did something similar in this thread:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/97645-Export-raster-attribute-table-into-CSV-using-Python-automation-!" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/97645-Export-raster-attribute-table-into-CSV-using-Python-automation-!&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;... I used the da cursor to access the RAT of a list of rasters and it worked. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to reproduce your error and in my case it also happened. Looking at the differences I noticed that in my case I don't supply a raster object to the cursor, but the path to the raster. In that case (apparently) arcpy has the possibility to interpret it as a "table" (at least when it's an integer raster with a RAT) ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So change it to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;locRas1 = os.path.join(env.workspace,'FlowD')
for r in arcpy.da.SearchCursor(&lt;STRONG&gt;locRas1&lt;/STRONG&gt;, ["VALUE", "COUNT"]):
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then it should work. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think you should mention this to Esri Support, since it would be a good thing if you can use a raster object in a da cursor...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:23:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/reading-a-raster-attribute-table/m-p/159052#M8885</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T08:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Raster Attribute table</title>
      <link>https://community.esri.com/t5/data-management-questions/reading-a-raster-attribute-table/m-p/159053#M8886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Xander.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My initial confusion about accessing the RAT table is functions like ListTables reveal no RATs. So its there but its not there sort of thing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But having all the raster parameters available with a Raster object is also quite handy, without having to go through a Describe object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, I see that if the permanent Raster is supplied to the da.SearchCursor, it reads the RAT fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Just a slight bit of inconsistency revealed here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Neil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 09:24:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/reading-a-raster-attribute-table/m-p/159053#M8886</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2013-12-02T09:24:12Z</dc:date>
    </item>
  </channel>
</rss>

