I can't seem to find a Describe property or any tool that will tell me whether a raster has an attribute table.

I can do it with a simple try/except statement on a test cursor or a table-specific tool, but those return relatively generic RuntimeError and ExecuteError, respectively. That seems messy and insufficient.

Is there a property/tool that will give me a simple boolean indicating whether the raster has an attribute table?

It's not that I want to ensure that there is one; it's that I simply want to test whether there is one.


The code you seek is this:

import arcpy
my_raster_layer = arcpy.Raster("dem")
if my_raster_layer.hasRAT:
     print "Has a VAT!"
     print "No VAT!"

For some reason they have decided to call it a RAT despite years of calling a VAT...

  • Thanks, so much! I will probably stick with the try/except, since it takes a while to initialize the Raster object, but this may come in handy in the future. – Tom Aug 30 '16 at 20:40
  • I wasn't aware of that property. Perfect! – jbchurchill Sep 1 '16 at 2:11

If it is important to you to always have a VAT you can use the Build Raster Attribute Table (Data Management) tool with the overwrite set to NONE (this is the default). That way if there is no VAT it will create a basic one and if one exists it will leave it alone (or update as specified by you).

Note: this will not work for rasters of type "32-bit floating point". But you could test for that with Get Raster Properties (Data Management)

  • Thanks, jb. But, it's not that I want to build one if it's not there. It's that I want to know whether I can proceed with some analysis. In this particular case, I don't have write access to the database containing the rasters, so if it doesn't have a RAT, I'll skip it. – Tom Aug 30 '16 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.