GeoServer Multi-band Image Using the Same Style


The requirement is to have data for ocean features with 12 channels, where each channel corresponds to data for a specific month. After publishing the layer, it should be possible to select the corresponding channel using a style and display the data for a specific month. The straightforward approach would be to create 12 copies of the style. However, for easier maintenance (which will most likely be done by myself), I wanted to find a way similar to "dynamic styles" where parameters can be obtained externally and the same style can be used to select different channels based on different parameters.

Here, I fell into a pitfall of my own assumption: the production environment is using a relatively old version of GeoServer, 2.11.x. When I was reading the documentation, I was referring to the latest version, and after testing it didn't work, I looked at the documentation for version 2.11. Although the documentation had a similar usage, it was not available for channel selection.

Therefore, this approach is only applicable to newer versions.

Layer Publishing#

The layer publishing can be done for multi-channel images.

Setting the Style#

The general channel selection for band fusion is done in the following format1:


In the style, 1, 2, and 3 channels correspond to (R, G, B).

For selecting a single channel to display, use the Function to get the "environment variable" and replace the default value:

            <Function name="env">

In this case, the channel name is wrapped in a Function object, which provides a default value of 1 when the value of m in env is empty. If m is not empty, its value is used as the channel name.

To select channel 2 for display, add &env=m:2 to the WMS request:


Here is a complete style:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="" xmlns:ogc="" xmlns:xlink="" xmlns:xsi="" xsi:schemaLocation="" version="1.0.0">
      <Title>A raster style</Title>
                        <SourceChannelName><ogc:Function name="env">
           <ColorMapEntry color="#0000ff" quantity="28.0"/>
           <ColorMapEntry color="#009933" quantity="30.0"/>
           <ColorMapEntry color="#ff9900" quantity="32.0" />
           <ColorMapEntry color="#ff0000" quantity="34.0"/>




In the end, because it was not easy to update the production environment version, I ended up copying 12*2 styles myself.


  1. GeoServer: RasterSymbolizer

Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.