2

I am trying to write an SLD that optionally takes a symbology for a PolygonSymbolizer and I can't work out how to do default to no symbology if the symbology env parameter is not set.

I have used the Variable Substitution example at http://docs.geoserver.org/stable/en/user/styling/sld-extensions/substitution.html as my basis.

<?xml version="1.0" encoding="UTF-8"?>
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld"
xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
  <sld:NamedLayer>
    <sld:Name>Configurable Polygon Style with Defaults</sld:Name>
    <sld:UserStyle>
      <sld:Name>Configurable Polygon Style with Defaults</sld:Name>
      <sld:Title>Configurable Polygon Style with Defaults</sld:Title>
      <sld:FeatureTypeStyle>
        <sld:Name>configurable_polygon</sld:Name>
        <sld:Rule>

          <sld:PolygonSymbolizer>


            <sld:Fill>
              <sld:GraphicFill>
                <sld:Graphic>
                  <sld:Mark>
                    <sld:WellKnownName>
                      <ogc:Function name="env">
                        <ogc:Literal>symbology</ogc:Literal>
                        <ogc:Literal>solid</ogc:Literal>
                      </ogc:Function>

                    </sld:WellKnownName>
                    <sld:Stroke>
                      <sld:CssParameter name="stroke">
                        <ogc:Function name="env">
                          <ogc:Literal>fill-color</ogc:Literal>
                          <ogc:Literal>#1A4F57</ogc:Literal>
                        </ogc:Function>
                      </sld:CssParameter>
                      <sld:CssParameter name="stroke-opacity">
                        <ogc:Function name="env">
                          <ogc:Literal>fill-opacity</ogc:Literal>
                          <ogc:Literal>0.8</ogc:Literal>
                        </ogc:Function>
                      </sld:CssParameter>
                      <sld:CssParameter name="stroke-width">
                        <ogc:Function name="env">
                          <ogc:Literal>fill-width</ogc:Literal>
                          <ogc:Literal>0.5</ogc:Literal>
                        </ogc:Function>
                      </sld:CssParameter>
                    </sld:Stroke>
                  </sld:Mark>
                  <sld:Size>
                    <ogc:Function name="env">
                      <ogc:Literal>fill-size</ogc:Literal>
                      <ogc:Literal>10</ogc:Literal>
                    </ogc:Function>
                  </sld:Size>
                </sld:Graphic>
              </sld:GraphicFill>
              <sld:CssParameter name="fill">
                <ogc:Function name="env">
                  <ogc:Literal>fill-color</ogc:Literal>
                  <ogc:Literal>#37747d</ogc:Literal>
                </ogc:Function>
              </sld:CssParameter>
              <sld:CssParameter name="fill-opacity">
                <ogc:Function name="env">
                  <ogc:Literal>fill-opacity</ogc:Literal>
                  <ogc:Literal>0.8</ogc:Literal>
                </ogc:Function>
              </sld:CssParameter>
            </sld:Fill>
            <sld:Stroke>
              <sld:CssParameter name="stroke">
                <ogc:Function name="env">
                  <ogc:Literal>stroke-color</ogc:Literal>
                  <ogc:Literal>#1A4F57</ogc:Literal>
                </ogc:Function>
              </sld:CssParameter>
              <sld:CssParameter name="stroke-opacity">
                <ogc:Function name="env">
                  <ogc:Literal>stroke-opacity</ogc:Literal>
                  <ogc:Literal>0.8</ogc:Literal>
                </ogc:Function>
              </sld:CssParameter>
            </sld:Stroke>
          </sld:PolygonSymbolizer>
        </sld:Rule>
      </sld:FeatureTypeStyle>
    </sld:UserStyle>
  </sld:NamedLayer>
</sld:StyledLayerDescriptor>

I want to be able to essentially test whether the 'symbology' env parameter in the WMS request has been set and apply the enclosed styling otherwise default to having no <sld:GraphicFill>.

Does anybody have any pointers?

1
  • Further reading and I'm wondering if I can use an <ogc:Filter> to do this? – Kehan Aug 6 '13 at 5:26
3

You have to add a filter that disables the rule completely if the env variable was not set

1
  • I figured that was probably the way forward but I could not work out how to create a filter that would only look for the env variable and not compare it to properties on the objects. Rereading docs.geoserver.org/latest/en/user/styling/sld-reference/… is looks like These operators contain two filter expressions to be compared. The first operand is often a <PropertyName>, but both operands may be any expression, function or literal value. – Kehan Aug 8 '13 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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