1

I have a dataset where multiple attributes need to be shown with the same symbol. I can achieve this using multiple 'PropertyIsEqualTo' operators nested within 'Or' logical operators, see below example;

    <ogc:Or>
    <ogc:PropertyIsEqualTo>
        <ogc:PropertyName>CURRENT_ST</ogc:PropertyName>
         <ogc:Literal>AB-LOC</ogc:Literal>
    </ogc:PropertyIsEqualTo>
    <ogc:PropertyIsEqualTo>
        <ogc:PropertyName>CURRENT_ST</ogc:PropertyName>
         <ogc:Literal>ABD</ogc:Literal>
    </ogc:PropertyIsEqualTo>
    </ogc:Or>

This seems a little inefficient, especially considering I have about 10 different symbol types each with about 10 contributing attributes. Ideally you would just clean the attribute data up, or add a symbol field that grouped them together but that is not an option in this case.

Is there a more efficient way of doing this?

For example being able to list the attributes something like the below would be great;

    <ogc:PropertyIsEqualTo>
        <ogc:PropertyName>CURRENT_ST</ogc:PropertyName>
         <ogc:Literal>'AB-LOC','ABD','ABC','DEF'</ogc:Literal>
    </ogc:PropertyIsEqualTo>
  • You may be able to do this in the QGIS OpenGeo Explorer plugin using the SLD editor feature on a WFS layer. The SLD editor will allow you to use QGIS symbology/rule based UI to update or change SLD on geoserver. – artwork21 Oct 13 '15 at 18:44
3

Geoserver provides a set of non-standard SLD functions in addition of the standard SLD features. The 'IN' operator is part of these non-standard functions. Something like that should work:

<ogc:Filter>
   <ogc:PropertyIsEqualsTo>
       <ogc:Function name="in4">
          <ogc:PropertyName>CURRENT_ST</ogc:PropertyName>
          <ogc:Literal>AB-LOC</ogc:Literal>
          <ogc:Literal>ABD</ogc:Literal>
          <ogc:Literal>ABC</ogc:Literal>
          <ogc:Literal>DEF</ogc:Literal>
       </ogc:Function>
       <ogc:Literal>true</ogc:Literal>
   </ogc:PropertyIsEqualsTo>
</ogc:Filter>

Note that in the function in4, 4 corresponds to the number of arguments you specify. Change it according to the number of values in your list. The OGC Filter 1.0 standard used in SLD 1.0 restrains a fixed number of arguments, that's why the in function is provided as a serie of inX where X is the actual number of arguments you have to apply.

You can have a look to this documentation page and example: http://docs.geoserver.org/stable/en/user/styling/sld-tipstricks/mixed-geometries.html#geometrytype-function

  • 1
    There is a drawback of using those functions though, the IN will be executed in memory, instead of being translated down to SQL or whatever native query facility the storage has. It's going to be fine for shapefiles though. Btw, there is no limitation to encoding functions down in SQL, it's just missing code that anybody can contribute to the project – Andrea Aime Oct 15 '15 at 10:53

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.