Convert color palette from raster to SymbologyEncoding

In the GIS world there currently exist many different raster file formats. Some of them can store color information about how to present the values stored in the file. The GeoTiff format for example can include information on how to visualize the raster values.

One widely-used way to describe such colorization-information are color-palettes. Color palettes typically contain up to 255 mappings of raster-values to RGB color values.

The great gdalinfo command line tool is able to show such color palette information from any supported raster file format. Let's see how gdalinfo could be used to show such information:

gdalinfo C:\some.tif
...
Band 1 Block=256x256 Type=Byte, ColorInterp=Palette
  Overviews: 2397x2103, 1199x1052, 600x526
  Color Table (RGB with 256 entries)
    0: 216,240,224,255
    1: 32,104,48,255
    2: 208,240,224,255
    3: 200,224,208,255
    4: 192,224,200,255
    5: 184,216,200,255
    6: 208,232,216,255
    7: 48,112,64,255
    8: 168,208,176,255
    9: 40,104,56,255
...

If  ColorInterp=Palette is reported by gdalinfo, a list of raster-value to color mappings follows.

Since version 1.7 AtlasStyler SLD/SE editor has support for raster files. When creating a style for a raster file, styling information is not automatically imported - unless it is already stored in a .sld file.

But recently there is a new function to import the output of gdalinfo for color palettes. Let's see how it works:

 

 

 

 

 

Last you would click the "Show XML code" or "Export all Layers as SLD". Since some time AtlasStyler is validating every SLD file automatically before saving: The resulting file can then be used with any WMS suporting SLD/SE, for example Geoserver.

Why would you want to do that?

Personally I have two typical usecases for this workflow:

1. Control transparency:

By converting the internal color-palette of a raster file to a SLD, it is easier to define transparency values. In the explame above, one would just delete a specific row, and the corresponding pixels are automatically transparent.

2. Save diskspace:

If you like to reduce the filesize of a RGB raster image, it can be very promosing to convert the three-band RGB image to a single-band image with a color palette - using gdal's rgb2pct tool. This conversion of course reduces the image quality (since the resulting image contains max. 255 colors), but also significantly reduces the disk usage. After this procedure I often need to control the transparency of the new file, resulting in reason 1.