5

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
7

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
1

Try using ApplyEnvironment on the raster variable.

#convert raster form meter to feet
raster = arcpy.Raster(raster_path) * 0.3048
arcpy.env.compression = 'LZW'
compressedRaster = arcpy.sa.ApplyEnvironment(raster)
compressedRaster.save(output_path)
  • Hi James, thanks for the tip. I couldn't seem to get it to work with GeoTIFF files, but perhaps I missed a step. – scw Feb 16 '11 at 23:42

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.