Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
share|improve this question
    
Does it have anything to do with LZW being proprietary? I have used this reference for my decision-making in regard to image format... arcpadteam.blogspot.com/2006/08/… –  Brad Nesom Feb 10 '11 at 20:09
    
Maybe with this added... packages.python.org/lzw/lzw-module.html –  Brad Nesom Feb 10 '11 at 20:21
    
The patents on LZW expired about 7 years back, but I can't get it to work with other compression methods either. –  scw Feb 10 '11 at 21:37
add comment

4 Answers

up vote 3 down vote accepted

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
share|improve this answer
add comment

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)
share|improve this answer
    
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
add comment

I don't think it is what you are looking for, I think it if for unicode strings

>>> dir(arcpy.env.compression) ... ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'islower', 'isnumeric', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

share|improve this answer
1  
Hi Dan, the dir above shows the methods available to the current value of arcpy.env.compression, which is a string, so I don't think this gets us very far, but thank you for looking into it. –  scw Feb 10 '11 at 23:24
    
Found that out shortly after Mr Downvote appeared without comment, in any event, it should have provided more than the unicode input stuff, but a list of acceptable values...had to get those from the online esri help at help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… for future reference –  Dan Patterson Feb 11 '11 at 18:09
add comment

I see a double quote in the online example...
arcpy.env.compression = "LZW"

share|improve this answer
    
It's python...single and double quotes are treated the same. –  Derek Swingley Feb 10 '11 at 23:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.