Skip to content

Allow usage of expressions in SelectChannelName

Andrea Aime edited this page Jun 19, 2018 · 9 revisions

Description

SLD allows to pick specific bands out of a raster, for rendering a false color map. Here is an example:

<RasterSymbolizer>
  <ChannelSelection>
    <RedChannel>
      <SourceChannelName>2</SourceChannelName>
    </RedChannel>
    <GreenChannel>
      <SourceChannelName>5</SourceChannelName>
    </GreenChannel>
    <BlueChannel>
      <SourceChannelName>7</SourceChannelName>
    </BlueChannel>
  </ChannelSelection>
<RasterSymbolizer>

The schema for SourceChannelName reports usage of a string, and the interfaces representing it are a match.

This was a suitable approach back when SLD 1.0 and SLD 1.1 were defined, but it's definitely showing its age with the current availability of multispectral imagery (e.g., Sentinel 2 has 13 bands) and hyperspectral imagery (drone mounted hyperspectral sensors have typically hundreds of bands). A way to pick the bands dynamically, without having to cast them in the SLD, is required.

Multispectral vs Hyperspectral

This proposal aims at replacing String with Expression in SourceChannelName, so that context free functions like env can be used to indicate which bands are to be used in a particular rendering session.

<RasterSymbolizer>
  <ChannelSelection>
    <RedChannel>
      <SourceChannelName>
          <ogc:Function name="env">
             <ogc:Literal>B1</ogc:Literal>
             <ogc:Literal>2</ogc:Literal>
          </ogc:Function>
      </SourceChannelName>
    </RedChannel>
    <GreenChannel>
      <SourceChannelName>
          <ogc:Function name="env">
             <ogc:Literal>B2</ogc:Literal>
             <ogc:Literal>5</ogc:Literal>
          </ogc:Function>
      </SourceChannelName>
    </GreenChannel>
    <BlueChannel>
      <SourceChannelName>
          <ogc:Function name="env">
             <ogc:Literal>B3</ogc:Literal>
             <ogc:Literal>7</ogc:Literal>
          </ogc:Function>
      </SourceChannelName>
    </BlueChannel>
  </ChannelSelection>
<RasterSymbolizer>

We assume that the SourceChannelName is seldomly used directly in client code, outside of building instances via factory/builders, so we propose a clean API break, while allowing the factories/builders to still work with fixed strings, along with expressions.

Assigned to Release

GeoTools 20.0, no backport planned

Status

Choose one of:

  • Under Discussion
  • In Progress
  • Completed
  • Rejected,
  • Deferred

Voting:

  • Andrea Aime: +1
  • Ben Caradoc-Davies: +1
  • Ian Turton: +1
  • Jody Garnett:
  • Simone Giannecchini: +1

Tasks

  1. Update API with a clean break
  2. Update SLD 1.0 parser and SLD 1.1 parser and the respective schemas used for validation
  3. Update rendering code to use expressions
  4. Update the StyleFactory and the style builder in gt-brewer to allow usage of Expression, while retaining the old method using String for backwards compatibility.
  5. Update the CSS parser to handle dynamic expression
  6. Make sure YSLD and MBStyle can at least compile and work as they used to (ideally, also work with expressions, if not too hard)
  7. Update documentation both in GeoTools and GeoServer

API Change

Before:

public interface SelectedChannelType {
    ...
    public String getChannelName();
    ...

After:

public interface SelectedChannelType {
    ...
    public Expression getChannelName();
    ...
Clone this wiki locally