2

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" 
 xmlns="http://www.opengis.net/sld" 
 xmlns:ogc="http://www.opengis.net/ogc" 
 xmlns:xlink="http://www.w3.org/1999/xlink" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <NamedLayer>
    <Name>custom_raster</Name>
    <UserStyle>
      <FeatureTypeStyle>
        <Rule>
          <Name>rule1</Name>
          <Title>Opaque Raster</Title>
          <Abstract>A raster with 100% opacity</Abstract>
          <RasterSymbolizer>
            <Opacity>1.0</Opacity>
            <ChannelSelection>
              <RedChannel>
                <SourceChannelName>${env('red',0)}</SourceChannelName>
              </RedChannel>
              <GreenChannel>
                <SourceChannelName>${env('green',1)}</SourceChannelName>
              </GreenChannel>
              <BlueChannel>
                <SourceChannelName>${env('blue',2)}</SourceChannelName>
              </BlueChannel>
            </ChannelSelection>
          </RasterSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

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?

2

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 Oct 9 '16 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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