1

In my requirement I have a float atribute (value) containing values between 0 and 10.

I want to use the interpolate function to color values between 0 and the threshold=5 in green colors and to interpolate the values between 5 and 10 with red colors. So it's somehow a combination of the interpolate and the categorize function of SLD. Is that possible?

<CssParameter name="stroke">
  <ogc:Function name="Interpolate">
                     <ogc:PropertyName>VALUE</ogc:PropertyName>
                     <ogc:Literal>-9999</ogc:Literal>
                     <ogc:Literal>#000000</ogc:Literal>
                     <ogc:Literal>0</ogc:Literal>
                     <ogc:Literal>#000000</ogc:Literal>
                     <ogc:Literal>0</ogc:Literal>
                     <ogc:Literal>#A51C1C</ogc:Literal>
                     <ogc:Literal>5</ogc:Literal>
                     <ogc:Literal>#FF9A9A</ogc:Literal>
                     <ogc:Literal>5</ogc:Literal>
                     <ogc:Literal>#00FF00</ogc:Literal>
                     <ogc:Literal>color</ogc:Literal>

Additionally I want to use the env parameter function of geoserver to pass the threshold value (5) in the WMS url. But I didn't find an example how to make that threshold dynamic.

  • 1
    Can you add the working sld for the first part to the question – Ian Turton Apr 2 '16 at 18:05
  • I added the sld part (it doesn't contain the same values but the idea is the same). Do you know how I can pass the threshold value by variable substitution? – MikeHuber Apr 2 '16 at 18:10
  • Just put the env function in where the 5s are? – Ian Turton Apr 2 '16 at 18:11
  • thanks :) I didn't know that's so easy, I can' mark your comment as an answer – MikeHuber Apr 2 '16 at 18:20
2

You can use the env function almost anywhere an expression is allowed in your SLD so your example becomes:

<CssParameter name="stroke">
  <ogc:Function name="Interpolate">
    <ogc:PropertyName>VALUE</ogc:PropertyName>
    <ogc:Literal>-9999</ogc:Literal>
    <ogc:Literal>#000000</ogc:Literal>
    <ogc:Literal>0</ogc:Literal>
    <ogc:Literal>#000000</ogc:Literal>
    <ogc:Literal>0</ogc:Literal>
    <ogc:Literal>#A51C1C</ogc:Literal>
    <ogc:Literal>
       <ogc:Function name="env">
          <ogc:Literal>break</ogc:Literal>
          <ogc:Literal>5</ogc:Literal>
       </ogc:Function>
    </ogc:Literal>
    <ogc:Literal>#FF9A9A</ogc:Literal>
    <ogc:Literal>
        <ogc:Function name="env">
            <ogc:Literal>break</ogc:Literal>
            <ogc:Literal>5</ogc:Literal>
        </ogc:Function>
    </ogc:Literal>
    <ogc:Literal>#00FF00</ogc:Literal>
    <ogc:Literal>color</ogc:Literal>

Assuming you have a variable called break it will be inserted, and if not then the default value of 5 will be used.

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.