0

I've bee trying to create a SLD style for a geoserver service. I would like to create a dynamic colormap to describe the scene with the contour of some areas (with a value over a certain value) highlighted.

I'm able to to the two steps separately, but I'm facing problems when I try to combine them

1) dynamic colormap:

<?xml version="1.0" encoding="UTF-8"?>
 <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0">
   <sld:NamedLayer>
     <sld:Name/>
     <sld:UserStyle>
       <sld:Name/>
       <sld:FeatureTypeStyle>
         <sld:Transformation>                       
           <ogc:Function name="ras:DynamicColorMap">
             <ogc:Function name="parameter">
               <ogc:Literal>data</ogc:Literal>
             </ogc:Function>
             <ogc:Function name="parameter">
               <ogc:Literal>opacity</ogc:Literal>
               <ogc:Function name="env">
                 <ogc:Literal>OPACITY</ogc:Literal>
                 <ogc:Literal>1.0</ogc:Literal>
               </ogc:Function>
             </ogc:Function>
             <ogc:Function name="parameter">
               <ogc:Literal>colorRamp</ogc:Literal>
               <ogc:Function name="colormap"        <ogc:Literal>rgb(241,248,241);rgb(214,234,214);rgb(187,221,187);rgb(161,207,161);rgb(134,194,134);rgb(107,180,107);rgb(80,167,80);rgb(53,153,53);rgb(26,140,26);rgb(0,127,0)</ogc:Literal>
                 <ogc:Function name="env">
                   <ogc:Literal>COLORSCALERANGE_MIN</ogc:Literal>
                   <ogc:Function name="bandStats">
                     <ogc:Literal>0</ogc:Literal>
                     <ogc:Literal>minimum</ogc:Literal>
                   </ogc:Function>
                 </ogc:Function>   
                 <ogc:Function name="env">
                   <ogc:Literal>COLORSCALERANGE_MAX</ogc:Literal>
                   <ogc:Function name="bandStats">
                     <ogc:Literal>0</ogc:Literal>
                     <ogc:Literal>maximum</ogc:Literal>
                   </ogc:Function>
                 </ogc:Function>                
                 <ogc:Function name="env">
                   <ogc:Literal>BELOWMINCOLOR</ogc:Literal>
                   <ogc:Literal>rgba(0,0,0,0)</ogc:Literal>
                 </ogc:Function>              
                 <ogc:Function name="env">
                   <ogc:Literal>ABOVEMAXCOLOR</ogc:Literal>
                   <ogc:Literal>rgba(0,0,0,0)</ogc:Literal>
                 </ogc:Function>             
                 <ogc:Function name="env">
                   <ogc:Literal>LOGSCALE</ogc:Literal>
                   <ogc:Literal>false</ogc:Literal>
                 </ogc:Function>             
                 <ogc:Function name="env">
                   <ogc:Literal>NUMCOLORBANDS</ogc:Literal>
                   <ogc:Literal>254</ogc:Literal>
                 </ogc:Function>    
               </ogc:Function>   
             </ogc:Function>
           </ogc:Function>        
         </sld:Transformation>
         <sld:Rule>
           <sld:RasterSymbolizer/>
         </sld:Rule>      
       </sld:FeatureTypeStyle>
     </sld:UserStyle>
   </sld:NamedLayer>
 </sld:StyledLayerDescriptor> 

2) contours:

<?xml version="1.0" encoding="UTF-8"?>
 <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0">
   <sld:NamedLayer>
     <sld:Name/>
     <sld:UserStyle>
       <sld:Name/>
       <sld:FeatureTypeStyle>
         <sld:Transformation>


            <ogc:Function name="ras:Contour">
              <ogc:Function name="parameter">
                <ogc:Literal>data</ogc:Literal>
              </ogc:Function>
              <ogc:Function name="parameter">
                <ogc:Literal>levels</ogc:Literal>
                <ogc:Literal>2.0</ogc:Literal>
                <ogc:Literal>3.0</ogc:Literal>
              </ogc:Function>
            </ogc:Function>

         </sld:Transformation>
         <Rule>
            <Name>rule1</Name>
            <Title>Contour Line</Title>
            <LineSymbolizer>
              <Stroke>
                <CssParameter name="stroke">#FF0000</CssParameter>
                <CssParameter name="stroke-width">1</CssParameter>
              </Stroke>
            </LineSymbolizer>
        </Rule>

       </sld:FeatureTypeStyle>
     </sld:UserStyle>
   </sld:NamedLayer>
 </sld:StyledLayerDescriptor>

I've been trying to concatenate :

<ogc:Function name="ras:DynamicColorMap">
...
</ogc:Function>
<ogc:Function name="ras:Contour">
...
</ogc:Function>

but clearly is not the right approach. Is it possible to combine these two styles or I have to create two separete ones? Or is there a function that I can add to ras:DynamicColorMap to highlight the borders of some areas?

1

They have to be in different FeatureTypeStyles because they produce different types of output (raster and lines) so the symbolizers would get confused if you combine them. But the following should work:

<?xml version="1.0" encoding="UTF-8"?>
 <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0">
   <sld:NamedLayer>
     <sld:Name/>
     <sld:UserStyle>
       <sld:Name/>
       <sld:FeatureTypeStyle>
         <sld:Transformation>                       
           <ogc:Function name="ras:DynamicColorMap">
             <ogc:Function name="parameter">
.....
           </ogc:Function>        
         </sld:Transformation>
         <sld:Rule>
           <sld:RasterSymbolizer/>
         </sld:Rule>      
       </sld:FeatureTypeStyle>
       <sld:FeatureTypeStyle>
         <sld:Transformation>
            <ogc:Function name="ras:Contour">
              <ogc:Function name="parameter">
.....
       </sld:FeatureTypeStyle>
     </sld:UserStyle>
   </sld:NamedLayer>
 </sld:StyledLayerDescriptor>
  • Awesome! indeed the fact of defining two sld:FeatureTypeStyle makes perfect sense! Thanks – Thomas Dec 19 '18 at 11:14

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.