2

I'm trying to make simple switch (if if else) statement in SLD with value coming from variable.

I'm calling Goeserver with parameter env=imageSize:A4.

Now based on that, I'd like to set cssProperty according to what value gets passed on. Pseudocode:

IF imageSize = A4
    cssProperty = 2
IF imageSize = A3
    cssProperty = 3
ELSE
    cssProperty = 1

I've come up with this:

<sld:CssParameter name="stroke-width">
  <ogc:Function name="if_then_else">
    <ogc:Function name="EqualTo">
      <ogc:PropertyName>pageSize</ogc:PropertyName>
      <ogc:Literal>A4</ogc:Literal>
    </ogc:Function>
    <ogc:Literal>2</ogc:Literal>
    <ogc:Literal>1</ogc:Literal>
    </ogc:Function>
</sld:CssParameter>

I can't get this to work, and after that I still need to implement second if statement.

2

Function names are case sensitive so your code will work with equalTo instead of EqualTo. Also your pageSize variable is an environment variable not a property.

But in your case it would probably be easier to use a recode function:

<sld:CssParameter name="stroke-width">
    <ogc:Function name="Recode">
      <ogc:Function name="env">
         <ogc:Literal>pageSize</ogc:Literal>
         <ogc:Literal>DEFAULT</ogc:Literal>
      </ogc:Function>
      <ogc:Literal>A4</ogc:Literal>
      <ogc:Literal>2</ogc:Literal> 
      <ogc:Literal>A3</ogc:Literal>
      <ogc:Literal>3</ogc:Literal> 
      <ogc:Literal>DEFAULT</ogc:Literal>
      <ogc:Literal>1</ogc:Literal>
     </ogc:Function>
 </sld:CssParameter>     

Then make sure your

| improve this answer | |

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.