12

Is it possible to use simple Math in an SLD file on Geoserver? Suppose I want to read a text size property from a database and multiply its value, how can I do this?

<sld:TextSymbolizer>
    ...
    <sld:CssParameter name="font-size">
        <ogc:PropertyName>text_size</ogc:PropertyName> * 2.1
    </sld:CssParameter>
    ...
</sld:TextSymbolizer>

This simple approach obviously doesn't work, so I thought there must be some way to achieve this.

1 Answer 1

17

You can use the math functions ogc:Mul ogc:Div ogc:Add & ogc:Sub to do simple maths on properties.

So your example would become:

<sld:CssParameter name="font-size">
    <ogc:Mul>
       <ogc:PropertyName>text_size</ogc:PropertyName>
       <ogc:Literal>2.5</ogc:Literal>
    </ogc:Mul>
</sld:CssParameter>

The only issue is that technically the SLD specification may not allow you to use a function in a CssParameter. However GeoServer is much more forgiving and will allow it.

If you ever need more complex functions see the reference page.

2
  • works like a charm Commented Jan 21, 2015 at 8:46
  • 1
    I found that <ogc:Mult> did not work for me, but <ogc:Mul> did. Commented Jun 8, 2016 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.