Compression (Environment setting)

Tools that honor the Compression environment will set the compression type when storing output raster datasets.

The primary benefits of compressing data are that compressed data requires less storage space and data display times will be quicker because there is less information to transmit.

ArcGIS can store compressed data in the following formats: IMG, JPEG, JPEG 2000, TIFF, Esri Grid, or in a geodatabase. When storing data in the geodatabase, the blocks of data are compressed before they are stored.

Data compression can be lossy (JPEG and JPEG 2000) or lossless (LZ77, PackBits, CCITT). Lossless compression means that the values of cells in the raster dataset are not changed or lost. You should choose lossless or no compression if the pixel values of the raster dataset will be used for analysis or deriving other data products.

The amount of compression will depend on the data and compression quality. The more homogeneous the data, the higher the compression ratio. The lower the compression quality, the higher the compression ratio. Lossy compression normally results in higher compression ratios when compared to lossless compression.

Usage notes

  • When storing data in a geodatabase, compression occurs before storage in the geodatabase.
  • File and enterprise geodatabases only support LZ77, JPEG, JPEG2000, and NONE compression types.
  • JPEG compression only works for unsigned 8-bit raster data and unsigned 12-bit data (stored as 16-bit data).
  • If JPEG, JPEG_YCbCr, or JPEG2000 is selected, you can also set the compression quality to control how much loss the image will be subjected to by the compression algorithm. The values of the pixels of an image compressed with a higher compression quality will be closer to those of the original image. Valid value ranges of compression quality are from 1 to 100. The default compression quality is 75. If you don't explicitly set a value, the default will be used.
  • The default compression type is LZ77 and it works for all types of raster data.
  • LERC compression is an image compression method that can divide raster into a number of pixel blocks, in which each pixel can be quantized and bit stuffed, based on a number of block statistics, including the maximum error allowable. The maximum error is a tolerance value that is applicable per pixel (not an average for the image).
  • The following table summarizes the valid compression types for each pixel depth:

    Valid compressions for each pixel depth

    CompressionPixel depth (8 bit)Pixel depth (16 bit)Additional information

    LZ77

    Yes

    Yes

    Any pixel depth.

    LERC

    Yes

    Yes

    As pixel depth increases, so does the efficiency of the compression algorithm.

    JPEG

    Yes

    Only 12-bit data; stored as 16-bit data

    JPEG_YCbCr

    Yes

    No

    JPEG2000

    Yes

    Yes

    PackBits

    Yes

    No

    1-bit to 8-bit data.

    LZW

    Yes

    Yes

    Any pixel depth.

    RLE

    Yes

    Yes

    Any pixel depth.

    CCITT_G3

    No

    No

    Only for 1-bit data.

    CCITT_G4

    No

    No

    Only for 1-bit data.

    CCITT_1D

    No

    No

    Only for 1-bit data.

    Valid compressions for each pixel depth
  • This setting is used for tools that create raster datasets in ArcGIS.

Dialog syntax

  • Compression—Choose which compression method to use when storing your data.
    • LZ77—Lossless compression that preserves all raster cell values. This is the default.
    • LERC—Lossless or lossy compression that divides the raster into a number of pixel blocks, in which each pixel can be quantized and bit stuffed, based on a number of block statistics, including the maximum error allowable.
    • JPEG—Lossy compression that uses the public JPEG compression algorithm. If you choose JPEG, you can also specify the compression quality. The valid compression quality value ranges are from 0 to 100, with 75 being the default. This compression can be used for .jpeg files, .tiff files, and geodatabases.
    • JPEG2000—Uses wavelet technology so rasters appear lossless. If you choose JPEG2000, you can also specify the compression quality. The valid compression quality value ranges are from 0 to 100, with 75 being the default. This compression can be used for JPEG 2000 files and geodatabases.
    • PackBitsPackBits compression for .tiff files.
    • LZW—Lossless compression that preserves all raster cell values.
    • RLE—Run-length encoding for .img files.
    • CCITT_G3—Lossless compression for 1-bit data.
    • CCITT_G4—Lossless compression for 1-bit data.
    • CCITT_1D—Lossless compression for 1-bit data.
    • JPEG_YCbCr—Lossless compression using the luma (Y) and chroma (Cb and Cr) color space components. If you choose JPEG_YCbCr, you can also specify the compression quality. The valid compression quality value ranges are from 0 to 100, with 75 being the default.
    • NONE—No compression will occur.
  • Compression quality (1-100)—When JPEG, JPEG_YCbCr, or JPEG2000 compression is chosen, the compression quality also must be specified. The valid compression quality value ranges are from 1 to 100, with 75 being the default.
  • Max error—When LERC compression is chosen, the maximum error also must be specified, which is expressed in the same units as the raster resolution. A maximum error of 0.000000 means that lossless compression will be used.

Scripting syntax

arcpy.env.compression = "compression_type {value}"

ParameterExplanation

compression_type (Required)

  • LZ77—Lossless compression preserves all raster cell values. This is the default.
  • LERC—Lossless or lossy compression divides the raster into a number of pixel blocks, in which each pixel can be quantized and bit stuffed, based on a number of block statistics, including the maximum error allowable.
  • JPEG—Lossy compression uses the public JPEG compression algorithm. If you choose JPEG, you can also specify the compression quality value. This compression can be used for .jpeg files, .tiff files, and geodatabases.

    The valid compression quality value ranges are from 0 to 100, with 75 being the default.

  • JPEG2000—Uses wavelet technology so rasters appear lossless. If you choose JPEG2000, you can also specify the compression quality value. This compression can be used for JPEG 2000 files and geodatabases.

    The valid compression quality value ranges are from 0 to 100, with 75 being the default.

  • PackBitsPackBits compression for .tiff files.
  • LZW—Lossless compression preserves all raster cell values.
  • RLE—Run-length encoding for .img files.
  • CCITT_G3—Lossless compression for 1-bit data.
  • CCITT_G4—Lossless compression for 1-bit data.
  • CCITT_1D—Lossless compression for 1-bit data.
  • JPEG_YCbCr—Lossless compression using the luma (Y) and chroma (Cb and Cr) color space components. If you choose JPEG_YCbCr, you can also specify the compression quality. The valid compression quality value ranges are from 0 to 100, with 75 being the default.
  • NONE—No compression will occur.

value (Optional)

When JPEG or JPEG2000 compression is chosen, the compression quality also must be specified. The valid compression quality value ranges are from 1 to 100, with 75 being the default.

When LERC compression is chosen, the maximum error also must be specified, which is expressed in the same units as the raster resolution. A maximum error of 0.000000 means that lossless compression will be used.

compression syntax

Script example

import arcpy

# Set the compression environment to LZ77
arcpy.env.compression = "LZ77"

# Set the compression environment to JPEG with a quality of 80
arcpy.env.compression = "JPEG 80"

Related topics