1

I am currently trying to batch compress a folder of .tif files using LZW compression in order to free up storage space. I've been using this script in ArcMap's python window, adapted from here:

# Import arcpy module
import arcpy, os

# Set the geoprocessing environments for the input and output folders
arcpy.env.workspace = r"Z:\ScannedImages\1300000\LZWCompressInput"
rasList = arcpy.ListRasters()
outWs = r"Z:\ScannedImages\1300000\LZWCompressOutput"

# Define the output settings for compression
arcpy.env.pyramid = "PYRAMIDS -1 BILINEAR JPEG 80"
arcpy.env.compression = "LZW"

# Run the Copy Raster tool
for ras in rasList:
        arcpy.CopyRaster_management(ras, outWs, "0", "", "", "NONE", "NONE", "", "NONE", "NONE")

but I keep getting the dreaded ERROR 999999 or ERROR 000472. Any ideas?

  • Is the last line in your script really not indented, or is that just a copy/paste error? Also, ERROR 000472 would indicate an issue with the grid name (length). If you run the tool from ArcGIS alone does it work? – Evil Genius May 5 '15 at 17:21
2

The output to CopyRaster should be a raster dataset, but your code uses a folder (your outWs). If still writing out to .tif format, something akin to this should do what you need:

for ras in rasList:
    arcpy.CopyRaster_management(ras, os.path.join(outWs, ras))
  • So close! the script ran and outputted all the .tif files, but they actually got bigger rather than being compressed. Any thoughts on why that happened? – purelyp93 May 5 '15 at 17:59
  • What was the compression before? – DWynne May 5 '15 at 18:09
  • The files were originally extracted from a .zip file but after they were extracted and before they were inputted into the script, there was no compression. – purelyp93 May 5 '15 at 18:32
  • @purelyp93: I can't speak to how the compression actually impacts file size, but the compression environment setting does appear to be getting used (you can see it if you check the properties). This is a different question that your original one, so you may wish to pose a second question. – DWynne May 5 '15 at 19:49
  • It seems to be a lossless vs. lossy issue, as I tried it with JPEG compression and the files are compressed as expected. Thanks for your help! – purelyp93 May 5 '15 at 20:04

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.