stylesgeoserversld

Geoserver style with condition


How can I use a different image (OnlineResource) depending on the attribute value? I have a feature with a 'number' attribute, I need to do something like: if number = 0 then OnlineResource = image 1 else OnlineResource = image 2


Solution

  • You can use two rules with filters in your SLD:

      <FeatureTypeStyle>
         <Rule>
           <Name>local-road</Name>
           <ogc:Filter>
             <ogc:PropertyIsEqualTo>
               <ogc:PropertyName>type</ogc:PropertyName>
               <ogc:Literal>local-road</ogc:Literal>
             </ogc:PropertyIsEqualTo>
           </ogc:Filter>
           <LineSymbolizer>
             <Stroke>
               <CssParameter name="stroke">#009933</CssParameter>
               <CssParameter name="stroke-width">2</CssParameter>
             </Stroke>
           </LineSymbolizer>
         </Rule>
         <Rule>
           <Name>secondary</Name>
           <ogc:Filter>
             <ogc:PropertyIsEqualTo>
               <ogc:PropertyName>type</ogc:PropertyName>
               <ogc:Literal>secondary</ogc:Literal>
             </ogc:PropertyIsEqualTo>
           </ogc:Filter>
           <LineSymbolizer>
             <Stroke>
               <CssParameter name="stroke">#0055CC</CssParameter>
               <CssParameter name="stroke-width">3</CssParameter>
             </Stroke>
           </LineSymbolizer>
         </Rule>
       </FeatureTypeStyle>