1

I am in need to use a postgres query inside an sld file. Based on the documentation, before testing the now() function, I decided to make a test with the max function. I want to style only the max value in the qtd_deteccoes property, ref to CODE 1. I retrieved the max value into the ogc:Literal tag, in other words (ogc:Literal has the value returned by the max function) and after that, I compared the value using the filter ogc:PropertyIsEqualTo. While validating the sld, GeoServer does not show any error, but I am not sure if the sld makes any sense. Could anyone give an insight to the code bellow?

<ogc:Filter>
    <ogc:PropertyIsEqualTo>    
         <ogc:PropertyName>qtd_deteccoes</ogc:PropertyName>
             <ogc:Literal>
                  <ogc:Function name="max">    
                   <ogc:PropertyName>qtd_deteccoes</ogc:PropertyName>    
             </ogc:Function>
            </ogc:Literal>
     </ogc:PropertyIsEqualTo>
</ogc:Filter>
      
1
  • @IanTurton does the code bellow make sense? At least the error is gone: <ogc:Filter> <ogc:PropertyIsEqualTo> <ogc:PropertyName>qtd_deteccoes</ogc:PropertyName> <ogc:Literal> <ogc:Function name="max"> <ogc:PropertyName>qtd_deteccoes</ogc:PropertyName> </ogc:Function> </ogc:Literal> </ogc:PropertyIsEqualTo> </ogc:Filter> Commented Sep 7, 2021 at 1:54

1 Answer 1

2

You are currently trying to compare the literal string:

         <ogc:Function name="max">    
               <ogc:PropertyName>qtd_deteccoes</ogc:PropertyName>    
         </ogc:Function>

with the value of the attribute qtd_deteccoes which will never be true, unless you have some very strange data.

If you remove the <ogc:Literal>s from your query:

<ogc:Filter>
    <ogc:PropertyIsEqualTo>    
         <ogc:PropertyName>qtd_deteccoes</ogc:PropertyName>
                  <ogc:Function name="max">    
                   <ogc:PropertyName>qtd_deteccoes</ogc:PropertyName>    
             </ogc:Function>
     </ogc:PropertyIsEqualTo>
</ogc:Filter> 

You are comparing the value of qtd_deteccoes with the result of the max function applied to the same value - which will always be true.

An SLD function only has access to the feature being rendered so you can't calculate the maximum of all the values in a FeatureCollection that way.

0

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.