Hello,
I was trying to create a style visualising traffic flows as stroke width on the road network like the attached image.
I was trying to submit the following to CSS Styling extension (GeoServer 2.9.1)
Unable to find source-code formatter for language: css. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
* {
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
<?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 tranlation, 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.
<?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 can live with the old SLD in the meantime but I think it is worth to enable users to use expressions for stroke-offset.
I have also tried this CSS in the refined new style editor but things were the same.
Many thanks,
|