Home    |    Concepts   |   API   |   Samples
Concepts > Rasters > Basic Principles
Raster Compression

ArcSDE allows LZ77, JPEG, and JPEG 2000 (JP2) data compression methods to reduce the amount of storage space used by each raster, thus producing smaller files resulting in better display performance for client applications. LZ77 compression is a loss-less compression method whereas JPEG and JP2 are lossy compression methods used mainly for compressing gray-scale and full color images.

The following table compares the three compression methods.

LZ77 JPEG JP2
Compression
  • Based on pixel value
  • Better compression with homogenous data
  • Compresses well for pixel data of low variability (i.e., color-mapped data or black & white)
Compression
  • Based on perceived pixel values and quality specified
  • Variable compression quality algorithm
  • Compresses well on pixel data high variability (i.e. RGB color imagery or elevation data)

 

Compression
  • Based on perceived pixel values and quality specified
  • Fixed and variable compression quality algorithm
  • Compresses well on pixel data high variability (i.e. RGB color imagery or elevation data)

 

Stores an offset length pair High quality = realistic data and larger file size
Lower quality = less realistic/coarse data and smaller file size
High quality = realistic data and larger file size
Lower quality = less realistic/coarse data and smaller file size
Can use with color maps
 
Cannot use with color maps Cannot use with color maps
Does not lose pixel values Pixel values are lost Pixel values are lost
Good for machine analysis Not appropriate for machine analysis Not appropriate for machine analysis
Applicable to all pixel depths Applies to only 8-bit unsigned pixel data Applies to only 8-bit unsigned pixel data

The amount of compression depends upon the data. The fewer unique cell values, the higher the compression ratio. The ArcSDE client performs compression and decompression. It also sends compressed data to the server at loading, and the server always returns compressed data to the client at retrieval. If retention of pixel values is important (e.g., categorical data or data used for analysis) use LZ77 compression. If individual pixel values are not important, as in the case of simple background, use JPEG or JP2 compression.

SE_RASTERATTR raster_attrib;

      CLIENT_DATA *client_data;

      SE_COMPRESSION_TYPE compression;

      CHAR name[8];

      LONG int_value;

      FLOAT flt_value;

 

      /* Set the compression type to one of its four possible values:   */

      /* lz77,                                                          */

      /* jpeg,                                                          */

      /* jpeg 2000                                                      */

      /* or no compression.                                             */

   

      compression = SE_COMPRESSION_LZ77;

 

      /* compression = SE_COMPRESSION_JPEG; */

      /* compression = SE_COMPRESSION_JP2;  */

      /* compression = SE_COMPRESSION_NONE; */

     

 

      /* Initialize the raster attribute structure for input. */

      rc = SE_rasterattr_create (raster_attrib,TRUE);

      check_error (rc, NULL, NULL, "SE_rasterattr_create");

 

      /* Set the compression type on the raster attribute structure data */

      rc = SE_rasterattr_set_compression_type (raster_attrib, compression);

      check_error (rc, NULL, NULL, "SE_rasterattr_set_compression_type");

 

      /* If the compression type is JPEG or JPEG 2000 the compression */

      /* property can also be set */

 

      /* For JPEG compression the name paramter is always set to "quality" */

      /* and the value can be an integer between 0 and 100 */

 

      if (compression == SE_COMPRESSION_JPEG)

      {    

           

            strcpy(name,"quality");

            int_value = 50;

 

            rc = SE_rasterattr_set_compression_property (raster_attrib,
                                                         name,

                                                         &int_value);

            check_error (rc, NULL, NULL,
                         "SE_rasterattr_set_compression_property");

      }

 

 

      /* For JPEG 2000 compression the name parameter can be set to either  */    

      /* "quality" to use a variable bitrate algorithm, or "bitrate" to use */

      /* a fixed bitrate compression */

 

     

      /* Use a JPEG 2000 variable bitrate compression with a quality set to */

      /* 120. */

  

      if (compression == SE_COMPRESSION_JP2)

      {

 

            strcpy(name,"quality");

            int_value = 120;

     

            rc = SE_rasterattr_set_compression_property (raster_attrib,

                                                         name,

                                                         &int_value);

            check_error (rc, NULL, NULL,
                         "SE_rasterattr_set_compression_property");

     

      }

 

      /* Use a JPEG 2000 fixed bitrate compression with a quality set to   */

      /* 1.6, which equates to a fixed compression rate of 20 percent for  */

      /* 8-bit data (8 * 0.20 = 1.6) and 10 percent (16 * 0.10 = 1.6) for  */

      /* 16 bit data                                                       */

 

      if (compression == SE_COMPRESSION_JP2)

      {

            strcpy(name,"bitrate");

            flt_value = 1.6;

 

            rc = SE_rasterattr_set_compression_property (raster_attrib,

                                                         name,
                                                         &flt_value);

            check_error (rc, NULL, NULL,  
                         "SE_rasterattr_set_compression_property");

     

      }
feedback | privacy | legal