[GIS] Compressing map algebra outputs from ArcPy

arcgis-10.0arcpymap-algebraspatial-analyst

When creating a raster map algebra output, is it possible to set its compression?

I'm creating a model which generates many hundreds of rasters, and currently each is being stored without any compression which quickly adds up. I expected to be able to use arcpy.env.compression but that seems to have no effect. Example script which produces this behavior:

import arcpy

arcpy.env.compression = 'LZW' # supported by GeoTIFF and most packages

map = Raster("raster.tif") + 100
map.save("raster_plus_100.tif") # would expect this output to have compresssion

Best Answer

I think the problem is that arcpy.env settings only apply to tools. Calling a method on an object is not technically a "tool". In a practical sense, the arcpy.env settings should apply to stuff like Raster.save() but it doesn't appear to work that way.

I was able to save a raster with compression by using arcpy.CopyRaster_management(). Something like this:

arcpy.env.compression = 'LZW'
t1 = arcpy.Raster('sample.tif') + 100
arcpy.CopyRaster_management(t1, 't1.tif')
del t1
Related Question