4

I have a raster with two bands. Both bands only have ones and zeros. I want to apply the following style:

Band1    Band2    Color
  0        0      #000000
  0        1      #ff0000
  1        0      #ffff00
  1        1      #ffffff

So I want to apply a style considering values on both bands, I searched on GeoServer documentation but I didn't find any similar example

1 Answer 1

2

I think the only way to do this is to transform it into a single band and color that in the normal way. Fortunately, GeoServer provides a way to do this using Rendering Transformations and Jiffle.

Something like (untested):

   <Transformation>
      <ogc:Function name="ras:Jiffle">
        <ogc:Function name="parameter">
          <ogc:Literal>coverage</ogc:Literal>
        </ogc:Function>
        <ogc:Function name="parameter">
          <ogc:Literal>script</ogc:Literal>
          <ogc:Literal>
            b1 = src[1];
            b2 = src[2];
            dest = (b1*2)+b2;
          </ogc:Literal>
        </ogc:Function>
      </ogc:Function>
    </Transformation>
    <Rule>
      <RasterSymbolizer>
        <Opacity>1.0</Opacity>
        <ColorMap type="values">
          <ColorMapEntry color="#000000" quantity="0"/>
          <ColorMapEntry color="#ff0000" quantity="1"/>
          <ColorMapEntry color="#ffff00" quantity="2"/>
          <ColorMapEntry color="#ffffff" quantity="3"/>
        </ColorMap>
      </RasterSymbolizer>
    </Rule>

Note: the use of values in the color map to color only pixels that match that value.

1
  • Thanks, I have tested it and works perfectly
    – David1212k
    Jun 11, 2020 at 9:39

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.