Uploaded image for project: 'GeoServer'
  1. GeoServer
  2. GEOS-7732

CSS: stroke-offset does not accept expressions

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: 2.9.1
    • Fix Version/s: 2.9.3, 2.10.1
    • Component/s: CSS
    • Labels:
      None
    • Environment:

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

      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)

      * {
        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 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.

      <?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,

        Attachments

          Issue links

            Activity

              People

              • Assignee:
                aaime Andrea Aime [Administrator]
                Reporter:
                GoSato Go Sato
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: