Sunday, 28 May 2017

raster - 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.



Answer




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")

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...