CSS: stroke-offset does not accept expressions

Description

Hello,
I was trying to create a style visualising traffic flows as stroke width on a bidirectional road network like the attached image.

I was trying to submit the following to CSS Styling extension (GeoServer 2.9.1)

1 2 3 4 5 6 7 * { stroke: #27b700; stroke-linecap: butt; stroke-linejoin: bevel; stroke-width : [ max(0.5, min(58.27, traffic_flow * 58.27 / 20000)) ]; stroke-offset: [ -0.5 * max(0.5, min(58.27, traffic_flow * 58.27 / 20000)) - 1 ]; }

The CSS was accepted without validation errors but the generated SLD turned out to be the following

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 <?xml version="1.0" encoding="UTF-8"?> <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0"> <sld:NamedLayer> <sld:Name>Default Styler</sld:Name> <sld:UserStyle> <sld:Name>Default Styler</sld:Name> <sld:FeatureTypeStyle> <sld:Rule> <sld:LineSymbolizer> <sld:Stroke> <sld:CssParameter name="stroke">#27b700</sld:CssParameter> <sld:CssParameter name="stroke-linejoin">bevel</sld:CssParameter> <sld:CssParameter name="stroke-width"> <ogc:Function name="max"> <ogc:Literal>0.5</ogc:Literal> <ogc:Function name="min"> <ogc:Literal>58.27</ogc:Literal> <ogc:Div> <ogc:Mul> <ogc:PropertyName>traffic_flow</ogc:PropertyName> <ogc:Literal>58.27</ogc:Literal> </ogc:Mul> <ogc:Literal>20000</ogc:Literal> </ogc:Div> </ogc:Function> </ogc:Function> </sld:CssParameter> </sld:Stroke> <sld:PerpendicularOffset>((-0.5*max([0.5], [min([58.27], [((traffic_flow*58.27)/20000)])]))-1)</sld:PerpendicularOffset> </sld:LineSymbolizer> </sld:Rule> <sld:VendorOption name="ruleEvaluation">first</sld:VendorOption> </sld:FeatureTypeStyle> </sld:UserStyle> </sld:NamedLayer> </sld:StyledLayerDescriptor>

You will see that the interpretor just put the stroke-offset to PerpendicularOffset without any translation, not even wrapped in ogc:Literal tag. Consequently, GeoSever throws an error when this SLD is applied.

The correct SLD should be like this. This has worked without errors as GeoServer allows expressions for PerpendicularOffsett.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 <?xml version="1.0" encoding="UTF-8"?> <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0"> <sld:NamedLayer> <sld:Name>Default Styler</sld:Name> <sld:UserStyle> <sld:Name>Default Styler</sld:Name> <sld:FeatureTypeStyle> <sld:Rule> <sld:LineSymbolizer> <sld:Stroke> <sld:CssParameter name="stroke">#27b700</sld:CssParameter> <sld:CssParameter name="stroke-linejoin">bevel</sld:CssParameter> <sld:CssParameter name="stroke-width"> <ogc:Function name="max"> <ogc:Literal>0.5</ogc:Literal> <ogc:Function name="min"> <ogc:Literal>58.27</ogc:Literal> <ogc:Div> <ogc:Mul> <ogc:PropertyName>traffic_flow</ogc:PropertyName> <ogc:Literal>58.27</ogc:Literal> </ogc:Mul> <ogc:Literal>20000</ogc:Literal> </ogc:Div> </ogc:Function> </ogc:Function> </sld:CssParameter> </sld:Stroke> <sld:PerpendicularOffset> <ogc:Add> <ogc:Mul> <ogc:Literal>-0.5</ogc:Literal> <ogc:Function name="max"> <ogc:Literal>0.5</ogc:Literal> <ogc:Function name="min"> <ogc:Literal>58.27</ogc:Literal> <ogc:Div> <ogc:Mul> <ogc:PropertyName>traffic_flow</ogc:PropertyName> <ogc:Literal>58.27</ogc:Literal> </ogc:Mul> <ogc:Literal>20000</ogc:Literal> </ogc:Div> </ogc:Function> </ogc:Function> </ogc:Mul> <ogc:Literal>-1</ogc:Literal> </ogc:Add> </sld:PerpendicularOffset> </sld:LineSymbolizer> </sld:Rule> <sld:VendorOption name="ruleEvaluation">first</sld:VendorOption> </sld:FeatureTypeStyle> </sld:UserStyle> </sld:NamedLayer> </sld:StyledLayerDescriptor>

I think it is worth to enable users to use expressions in stroke-offset.
Please note that I have also tried this in the refined new style editor (the default one, not the extension one) but things were the same.

Many thanks,

Environment

Amazon Linux (Linux 4.4.19-29.55.amzn1.x86_64 x86_64)
Oracle JRE 1.8.0_74
Tomcat 7.0.70

Status

Assignee

Andrea Aime

Reporter

Go Sato

Triage

Fix versions

Affects versions

2.9.1

Components

Priority

Medium
Configure