# Preserve attribute table while using Extract by Mask in ArcGIS

When using the Extract by Mask function on a raster with several columns (beyond value and count) in the attribute table, the resulting raster does not have all the columns (it only has value and count).

Is there a way to conduct extract by mask and also preserve the columns?

Please note that this is part of a script in python.

• Have you tried using Clip Raster (Data Management)? – Aaron Sep 1 '14 at 15:41
• The issue with clip raster is that I need to specify the bounding rectangle. is there a way to do that programatically in python? – user1186 Sep 1 '14 at 15:59

Clip (Data Management) preserves the raster attributes. You can specify the bounding box in a scripting environment too. For example, from the ESRI documentation:

import arcpy
ws = r'C:\temp'  #workspace
fc = r'C:\path\to\featureclass
inRaster = r':\path\to\raster.tif'
outRaster = os.path.join(ws, "outRaster.tif")

# Create bounding box from polygon (xmin, ymin, xmax, ymax)
desc = arcpy.Describe(fc)
rectangle = "%s %s %s %s" % (desc.extent.XMin, desc.extent.YMin, desc.extent.XMax,   desc.extent.YMax)

arcpy.Clip_management(inRaster, rectangle, outRaster, "#", "#", "NONE")

• Thanks Aaron, I meant how to get boundingBox from a polygon programmatically? I do not know these values before hand. – user1186 Sep 1 '14 at 16:08
• In this case, the raster output is a tiff: outRaster = os.path.join(ws, "outRaster.tif"). – Aaron Mar 23 '18 at 18:05