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:CssParameter name="font-size">
        <ogc:PropertyName>text_size</ogc:PropertyName> * 2.1

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

2 Answers 2


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">

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.

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

As far as I'm aware GeoServer cannot do any math embedded into the SLD.
You can however create a rule in the SLD that can read <ogc:PropertyName>text_size</ogc:PropertyName> with a filter, and define your own text size.
The GeoServer SLD Cookbook has some examples of using <ogc:Filter>

  • Seems like this is now working. Please check with versions 2.12.1 and up.
    – ragnvald
    Sep 26, 2019 at 21:47

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.