<?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: ArcGIS 10.4.1 arcpy - Has Raster Attribute Table been built? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-10-4-1-arcpy-has-raster-attribute-table/m-p/854798#M3958</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In case anyone else has the same question, here's what I've come up with...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It appears that when a raster attribute table is created in a file geodatabase, it is given the same name as the raster with "VAT_" pre-pended; e.g., "VAT_rasterName". So, in my code, I am now doing the following to determine if the RAT has already been built (note: path2FeatureClass points to the Feature Class the raster was created with):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp; import os

&amp;nbsp;&amp;nbsp; &amp;nbsp; :

&amp;nbsp; &amp;nbsp;path2Fgdb = os.path.dirname(path2Raster)
&amp;nbsp;&amp;nbsp; ratName = "VAT_" + os.path.basename(path2Raster)
&amp;nbsp;&amp;nbsp; ratTable = os.path.join(path2Fgdb, ratName)

&amp;nbsp;&amp;nbsp; if not (arcpy.Exists(ratTable)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.BuildRasterAttributeTable_management (&lt;SPAN&gt;path2Raster&lt;/SPAN&gt;, "NONE")

&amp;nbsp;&amp;nbsp; fields = arcpy.ListFields(&lt;SPAN&gt;path2Raster&lt;/SPAN&gt;, "myFieldName")
&amp;nbsp;&amp;nbsp; if (fields is None or len(fields) &amp;lt; 1):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.JoinField_management(&lt;SPAN&gt;path2Raster&lt;/SPAN&gt;, "Value", path2FeatureClass, "OBJECTID", "")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure if it's safe to do this (in terms of future support), but for the moment it appears to be doing what I need it to do.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Cheers,&lt;/P&gt;&lt;P&gt;jtm&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 17:00:10 GMT</pubDate>
    <dc:creator>JoanneMcGraw</dc:creator>
    <dc:date>2021-12-12T17:00:10Z</dc:date>
    <item>
      <title>ArcGIS 10.4.1 arcpy - Has Raster Attribute Table been built?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-10-4-1-arcpy-has-raster-attribute-table/m-p/854797#M3957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an arcpy script that I run in ArcGIS Catalog 10.4.1. The code creates a raster attribute table for a raster; a step which takes a couple of minutes to execute. Subsequent to that step, fields from a feature class are joined to it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In an effort to make the code faster, I would like to check if the raster attribute table has already been created by a previous run and then check if the fields from the feature class have already been appended so I can skip these two processes. I know how to check the fields, but can't figure out how to find out if the RAT has already been built.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I ListFields on the raster, it tells me that fields exist whether the RAT has been created or not; I imagine because they exist in memory. However, if I assume the existence of fields indicates the RAT exists, when I try to JoinFields, it fails because the RAT doesn't.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If worse comes to worst, I suppose I can try/except to JoinFields and if it fails because it can't find the table, I can build&amp;nbsp;the RAT and then try JoinFields again. However, I&amp;nbsp;am surprised I can't find a way to determine whether it already exists.&amp;nbsp;ListTables doesn't return a RAT even it if does exist.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is anyone aware of a method for finding out if a Raster Attribute Table has already been built?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;jtm&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Sep 2018 14:58:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-10-4-1-arcpy-has-raster-attribute-table/m-p/854797#M3957</guid>
      <dc:creator>JoanneMcGraw</dc:creator>
      <dc:date>2018-09-11T14:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS 10.4.1 arcpy - Has Raster Attribute Table been built?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-10-4-1-arcpy-has-raster-attribute-table/m-p/854798#M3958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In case anyone else has the same question, here's what I've come up with...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It appears that when a raster attribute table is created in a file geodatabase, it is given the same name as the raster with "VAT_" pre-pended; e.g., "VAT_rasterName". So, in my code, I am now doing the following to determine if the RAT has already been built (note: path2FeatureClass points to the Feature Class the raster was created with):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp; import os

&amp;nbsp;&amp;nbsp; &amp;nbsp; :

&amp;nbsp; &amp;nbsp;path2Fgdb = os.path.dirname(path2Raster)
&amp;nbsp;&amp;nbsp; ratName = "VAT_" + os.path.basename(path2Raster)
&amp;nbsp;&amp;nbsp; ratTable = os.path.join(path2Fgdb, ratName)

&amp;nbsp;&amp;nbsp; if not (arcpy.Exists(ratTable)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.BuildRasterAttributeTable_management (&lt;SPAN&gt;path2Raster&lt;/SPAN&gt;, "NONE")

&amp;nbsp;&amp;nbsp; fields = arcpy.ListFields(&lt;SPAN&gt;path2Raster&lt;/SPAN&gt;, "myFieldName")
&amp;nbsp;&amp;nbsp; if (fields is None or len(fields) &amp;lt; 1):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.JoinField_management(&lt;SPAN&gt;path2Raster&lt;/SPAN&gt;, "Value", path2FeatureClass, "OBJECTID", "")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure if it's safe to do this (in terms of future support), but for the moment it appears to be doing what I need it to do.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Cheers,&lt;/P&gt;&lt;P&gt;jtm&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 17:00:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-10-4-1-arcpy-has-raster-attribute-table/m-p/854798#M3958</guid>
      <dc:creator>JoanneMcGraw</dc:creator>
      <dc:date>2021-12-12T17:00:10Z</dc:date>
    </item>
  </channel>
</rss>

