5

I have a dynamic style in Geoserver, like below:

    <sld:ColorMap>
      <sld:ColorMapEntry color="#2c7bb6" quantity="${env('low',0)}" label="${env('low',0)}"/>
      <sld:ColorMapEntry color="#64a5cd" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 1 / 9}"/>
      <sld:ColorMapEntry color="#9dcfe4" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 2 / 9}"/>
      <sld:ColorMapEntry color="#c7e6db" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 3 / 9}"/>
      <sld:ColorMapEntry color="#edf7c9" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 4 / 9}"/>
      <sld:ColorMapEntry color="#ffedaa" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 5 / 9}"/>
      <sld:ColorMapEntry color="#fec980" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 6 / 9}"/>
      <sld:ColorMapEntry color="#f99e59" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 7 / 9}"/>
      <sld:ColorMapEntry color="#e85b3a" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 8 / 9}"/>
      <sld:ColorMapEntry color="#d7191c" quantity="${env('high',0)}" label="${env('high',0)}"/>      
    </sld:ColorMap>

An example request:

/geoserver/temper/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&LAYER=temper:A%C3%91O2017&WIDTH=30&HEIGHT=5&transparent=true&STYLE=estilo_fijo&env=low:11;high:13;&LEGEND_OPTIONS=fontSize:15;fontColor:0xFFFFFF0;fontStyle:bold;dpi:180;mx:0.2;my:0.2;dx:2;dy:2;absoluteMargins:True;

I was expecting labels to take the values provided with the enviroment variables passed in the GetLegendGraphics request, as it's working with the quantity parameter for GetMap requests.

The output image i'm getting:

enter image description here

It seems that whatever you pass in the label parameter is treated as string, and dynamic values are not working with the syntax used.

So it's possible and I'm using the wrong syntax? Or it's not possible to make the label dynamic?

Also, Geoserver says my style is not valid and get some errors during the validation, but the style is working:

line 18: cvc-attribute.3: The value '${env('low',0) + (env('high',0) - env('low',0)) * 7 / 9}' of attribute 'quantity' on element 'sld:ColorMapEntry' is not valid with respect to its type, 'double'.

5

The documentation does not include "label" as an attribute that can take expressions, it states "Most of the ColorMapEntry attributes (color, quantity and opacity) can be defined using cql expressions". So only color, quantity and opacity can use expressions, see also:

http://docs.geoserver.org/stable/en/user/styling/sld/reference/rastersymbolizer.html#cql-expressions

Not all is lost though, if you want you push for "label" to also support expressions, see the expected process here:

https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

  • Ok Thank you very much, I'll request this feature as soon as possible. By the way you saved me hours of finding if it was possible. Don't you think it would be nice if that exist? – Jose Hermosilla Rodrigo Jan 11 '18 at 11:40
  • 1
    I have never needed it, but sure, would'nt hurt to have it :) – Andrea Aime Jan 11 '18 at 13:13

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.