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.

  • 1
    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
  • 1
    @user1186 Post updated to address your comments. – Aaron Sep 1 '14 at 16:33
  • I recently ran into this problem and wanted to clarify that if your output raster is in the Esri Grid format, you will still lose your raster attribute table with the Clip (Data Management) tool, so make sure the output is a tiff – Marina Mar 23 '18 at 17:47
  • In this case, the raster output is a tiff: outRaster = os.path.join(ws, "outRaster.tif"). – Aaron Mar 23 '18 at 18:05

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.