1

I have vector point data being served via Geoserver, with layer styling being applied using an SLD stylesheet. I've created a number of styling rules to symbolise these points, and I'd like to customise these rules by filtering each point by four individual attribute fields so that the points are only shown on the map when all four tests are True.

I have tried to achieve this by including all four of my filter tests inside a <ogc:And> logical operator:

<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:And>
        <ogc:PropertyIsGreaterThanOrEqualTo>
            <ogc:PropertyName>rate_time</ogc:PropertyName>
            <ogc:Literal>-2.5</ogc:Literal>
        </ogc:PropertyIsGreaterThanOrEqualTo>
        <ogc:PropertyIsLessThan>
            <ogc:PropertyName>rate_time</ogc:PropertyName>
            <ogc:Literal>-1.0</ogc:Literal>
        </ogc:PropertyIsLessThan>
        <ogc:PropertyIsLessThanOrEqualTo>
            <ogc:PropertyName>sig_time</ogc:PropertyName>
            <ogc:Literal>0.01</ogc:Literal>
        </ogc:PropertyIsLessThanOrEqualTo>
        <ogc:PropertyIsGreaterThan>
            <ogc:PropertyName>valid_obs</ogc:PropertyName>
            <ogc:Literal>25</ogc:Literal>
        </ogc:PropertyIsGreaterThan>
    </ogc:And>
</ogc:Filter>

However, this is not working correctly, as some points continue to show on the map despite at least one of the four tests returning False. I suspect this is because <ogc:And> only supports two filter operator elements:

The content for "And" and "Or" is two filter operator elements [link]

What is the recommended way to apply multiple (e.g. four in this particular case) attribute tests within a single Geoserver SLD filter?

1 Answer 1

3

I think unfortunately, you need to do lots of nesting... XML is verbose.

<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
  <ogc:And>
    <ogc:And>
      <ogc:PropertyIsGreaterThanOrEqualTo>
        <ogc:PropertyName>rate_time</ogc:PropertyName>
        <ogc:Literal>-2.5</ogc:Literal>
      </ogc:PropertyIsGreaterThanOrEqualTo>
      <ogc:PropertyIsLessThan>
        <ogc:PropertyName>rate_time</ogc:PropertyName>
        <ogc:Literal>-1.0</ogc:Literal>
      </ogc:PropertyIsLessThan>
    </ogc:And>
    <ogc:And>
      <ogc:PropertyIsLessThanOrEqualTo>
        <ogc:PropertyName>sig_time</ogc:PropertyName>
        <ogc:Literal>0.01</ogc:Literal>
      </ogc:PropertyIsLessThanOrEqualTo>
      <ogc:PropertyIsGreaterThan>
        <ogc:PropertyName>valid_obs</ogc:PropertyName>
        <ogc:Literal>25</ogc:Literal>
      </ogc:PropertyIsGreaterThan>
    </ogc:And>
  </ogc:And>
</ogc:Filter>
1
  • 1
    Just a side note: The annoying limit of two conditions per logical operator is not a result of the verbosity of XML. It seems to actually be a problem with the Geoserver implementation of the OGC SLD standard, because the standard says a BinaryLogicOpType can have two or more sub-elements but Geoserver docs say there is a limit of two.
    – rooby
    Feb 3, 2022 at 1:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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