1

I am using GeoServer 2.19, and I have a wind coverage view from a grib file (uwnd,vwnd components), and I want it to become a wind speed raster layer.

When I preview it with a raster style, I realised that the color of raster just draw with only uwnd component, not the value of wind speed value(sqrt(uwnd^2 + vwnd^2)).

I saw rendering-transform can do what I want(something like value transform?!), but the example on it is not my needs. (I just need a raster layer of wind speed value, neither wind barbs nor wind arrows)

so I tried to edit it, then it doesn't worked.

My SLD style:

<StyledLayerDescriptor
    version="1.0.0"
    xmlns="http://www.opengis.net/sld"
    xmlns:gml="http://www.opengis.net/gml"
    xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.opengis.net/sld ./StyledLayerDescriptor.xsd">
    <NamedLayer>
        <Name>wind</Name>
        <UserStyle>
            <Title>wind</Title>
            <FeatureTypeStyle>
                <Transformation>
                    <ogc:Function name="Categorize">
                        <!-- Value to transform -->
                        <ogc:Function name="sqrt">
                            <ogc:Add>
                                <ogc:Mul>
                                    <ogc:PropertyName>uwnd</ogc:PropertyName>
                                    <ogc:PropertyName>uwnd</ogc:PropertyName>
                                </ogc:Mul>
                                <ogc:Mul>
                                    <ogc:PropertyName>vwnd</ogc:PropertyName>
                                    <ogc:PropertyName>vwnd</ogc:PropertyName>
                                </ogc:Mul>
                            </ogc:Add>
                        </ogc:Function>
                        <ogc:Literal>8</ogc:Literal>
                        <ogc:Literal>1.543333332</ogc:Literal>
                        <ogc:Literal>32</ogc:Literal>
                    </ogc:Function>
                </Transformation>
                <Rule>
                    <RasterSymbolizer>
                        <Size>
                            <ogc:Function name="Categorize">
                                <!-- Value to transform -->
                                <ogc:Function name="sqrt">
                                    <ogc:Add>
                                        <ogc:Mul>
                                            <ogc:PropertyName>uwnd</ogc:PropertyName>
                                            <ogc:PropertyName>uwnd</ogc:PropertyName>
                                        </ogc:Mul>
                                        <ogc:Mul>
                                            <ogc:PropertyName>vwnd</ogc:PropertyName>
                                            <ogc:PropertyName>vwnd</ogc:PropertyName>
                                        </ogc:Mul>
                                    </ogc:Add>
                                </ogc:Function>
                                <ogc:Literal>8</ogc:Literal>
                                <ogc:Literal>1.543333332</ogc:Literal>
                                <ogc:Literal>32</ogc:Literal>
                            </ogc:Function>
                        </Size>
                        <Graphic>
                            <ColorMap type="ramp">
                                <ColorMapEntry color="#f9f9f9" quantity="0" label="0m/s"/>
                                <ColorMapEntry color="#d860aa" quantity="2" label="2m/s"/>
                                <ColorMapEntry color="#9757cc" quantity="4" label="4m/s"/>
                                <ColorMapEntry color="#5774cc" quantity="6" label="6m/s"/>
                                <ColorMapEntry color="#57cccc" quantity="8" label="8m/s"/>
                                <ColorMapEntry color="#aacc57" quantity="10" label="10m/s"/>
                                <ColorMapEntry color="#ccc457" quantity="12" label="12m/s"/>
                                <ColorMapEntry color="#cc8b57" quantity="14" label="14m/s"/>
                                <ColorMapEntry color="#cc5757" quantity="16" label="16m/s"/>
                                <ColorMapEntry color="#775046" quantity="18" label="18m/s"/>
                                <ColorMapEntry color="#000000" quantity="20" label="20m/s"/>
                            </ColorMap>
                        </Graphic>
                    </RasterSymbolizer>
                </Rule>
            </FeatureTypeStyle>
        </UserStyle>
    </NamedLayer>
</StyledLayerDescriptor>

Error message:

code="internalError"Rendering process failed. Layers:wind-2020-11-23
Don't know how to handle the results of the transformation, the supported result types are FeatureCollection, GridCoverage2D and GridCoverage2DReader, but we got: class java.lang.String

Is anyone have experience of it?

1

1 Answer 1

1

I found the solution to the above problem using ras:Jiffle script as follows:

<Transformation>
  <ogc:Function name="ras:Jiffle">
    <ogc:Function name="parameter">
      <ogc:Literal>coverage</ogc:Literal>
    </ogc:Function>
    <ogc:Function name="parameter">
      <ogc:Literal>script</ogc:Literal>
      <ogc:Literal>
        u = src[0];
        v = src[1];
        dest = sqrt(u*u+v*v) * 0.01;               
      </ogc:Literal>
    </ogc:Function> 
  </ogc:Function>
</Transformation>
<sld:Rule>
  <sld:RasterSymbolizer>   
    <ColorMap>
      <ColorMapEntry color="#5E70B4" quantity="0" opacity="1.0"/>
      <ColorMapEntry color="#3B68A1" quantity="1" opacity="1.0"/>
      <ColorMapEntry color="#4078A5" quantity="2" opacity="1.0"/>              
    </ColorMap>
  </sld:RasterSymbolizer>

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.