2

I have a sld style:

<se:FeatureTypeStyle>
    <se:Rule>
      <se:Name> 0 - 100 </se:Name>
      <se:Description>
        <se:Title> >101 </se:Title>
      </se:Description>
      <ogc:Filter>
        <ogc:PropertyIsGreaterThanOrEqualTo>
            <ogc:PropertyName>count</ogc:PropertyName>
            <ogc:Literal>101</ogc:Literal>
          </ogc:PropertyIsGreaterThanOrEqualTo>
      </ogc:Filter>
      <se:PolygonSymbolizer>
        <se:Fill>
          <se:SvgParameter name="fill">#ff0000</se:SvgParameter>
        </se:Fill>
      </se:PolygonSymbolizer>
    </se:Rule>
    <se:Rule>
      <se:Name> 51- 100 </se:Name>
      <se:Description>
        <se:Title> 51- 100</se:Title>
      </se:Description>
      <ogc:Filter>
        <ogc:And>
          <ogc:PropertyIsGreaterThanOrEqualTo>
            <ogc:PropertyName>count</ogc:PropertyName>
            <ogc:Literal>51</ogc:Literal>
          </ogc:PropertyIsGreaterThanOrEqualTo>
          <ogc:PropertyIsLessThan>
            <ogc:PropertyName>count</ogc:PropertyName>
            <ogc:Literal>100</ogc:Literal>
          </ogc:PropertyIsLessThan>
        </ogc:And>
      </ogc:Filter>
      <se:PolygonSymbolizer>
        <se:Fill>
          <se:SvgParameter name="fill">#00ff00</se:SvgParameter>
        </se:Fill>
      </se:PolygonSymbolizer>
    </se:Rule>
    <se:Rule>
      <se:Name> 0- 50 </se:Name>
      <se:Description>
        <se:Title> 0- 50 </se:Title>
      </se:Description>
      <ogc:Filter>
        <ogc:And>
          <ogc:PropertyIsLessThan>
            <ogc:PropertyName>count</ogc:PropertyName>
            <ogc:Literal>50</ogc:Literal>
          </ogc:PropertyIsLessThan>
        </ogc:And>
      </ogc:Filter>
      <se:PolygonSymbolizer>
        <se:Fill>
          <se:SvgParameter name="fill">#0000ff</se:SvgParameter>
        </se:Fill>
      </se:PolygonSymbolizer>
    </se:Rule>
  </se:FeatureTypeStyle>

So depended on field count i got:

>=101  Red polygon
51-100 Green polygon
<=50   Blue polygon

Now i add CQL filter into wms request to show features with count <=100:

CQL_FILTER=count%3C%3D100

So i got Green and Blue polygons only.
And here my question.
Can i modifi my SLD to it dynamicaly change filters values? For example above, after adding CQL filter i got features with count <=100. And i want to filters changed like:

51-100 Red polygon
<=50   Green polygon

It possible make something like this?

3

GeoServer provides an env function that allows you to set values within the SLD using parameters passed in as part of the URL.

So your filter could become something like:

   <ogc:And>
      <ogc:PropertyIsGreaterThanOrEqualTo>
        <ogc:PropertyName>count</ogc:PropertyName>
        <ogc:Function name="env">
          <ogc:Literal>low</ogc:Literal>
          <ogc:Literal>51</ogc:Literal>
        </ogc:Function>
      </ogc:PropertyIsGreaterThanOrEqualTo>
      <ogc:PropertyIsLessThan>
        <ogc:PropertyName>count</ogc:PropertyName>
        <ogc:Function name="env">
          <ogc:Literal>high</ogc:Literal>
          <ogc:Literal>100</ogc:Literal>
        </ogc:Function>
      </ogc:PropertyIsLessThan>
    </ogc:And>

And then you can change them by adding &env=low:1;high=52 to your getMap request.

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.