I am trying various ways to have a programatic way of combining various bands of a tiff file into the red, green, blue channels.

I tried the CQL way, eg see below

This is my SLD

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" 
 xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 
          <Title>Opaque Raster</Title>
          <Abstract>A raster with 100% opacity</Abstract>

I call it using ENV=red:1;blue:3;green:5 but I am getting the following message

Caused by: java.lang.IllegalArgumentException: Band number -1 is not valid.
Caused by: java.lang.NumberFormatException: For input string: "${env('red',0)}"

It doesn't seem to allow CQL expressions where I am placing them... yet doesn't complain when I validate. Any idea?

1 Answer 1


The SLD specification allows only static names in the SourceChannelName element. GeoServer/GeoTools have not yet extended them to support expressions, it would be possible with some resourcing, see here: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Btw, why are you getting no errors? Because the spec says the channel name is a string, and "${env('red',0)}" is a string. The special CQL syntax is only used in selected attributes, as an extension, because there is no way to allow a normal OGC expression.

  • Thanks Andrea, makes sense. In the end I used an SLD_BODY instead. BTW, took me a while to find out how to use it, until I realised the name layer needs to match the actual layer it is applied to.
    – Thomas
    Commented Oct 9, 2016 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.