6

Is it possible to use math in SLD file in Geotools? I want to get Orientation for lines and calculate its sine/cosine and then multiply it with some value. But when I do this nothing shows up. Here is part polygon symbolizer that I am using.

<PolygonSymbolizer>
<Geometry>
    <ogc:Function name="buffer">
        <ogc:PropertyName>the_geom</ogc:PropertyName>
        <ogc:PropertyName>Buffer</ogc:PropertyName>
    </ogc:Function>
</Geometry>  
<Fill>
    <GraphicFill>
        <Graphic>
            <Mark>
                <WellKnownName>wkt://LINESTRING( 
                0 
                0,     
                    <ogc:Mul>
                        <ogc:PropertyName>Orientation</ogc:PropertyName>
                        <ogc:Literal>200</ogc:Literal>
                    </ogc:Mul> 
                    33 )</WellKnownName>
                <Stroke>
                    <CssParameter name="stroke">#000000</CssParameter>
                    <CssParameter name="stroke-width">1</CssParameter>
                </Stroke>
            </Mark>
        </Graphic>
    </GraphicFill>
</Fill>

Function for multiplication is

<ogc:Mul>
    <ogc:PropertyName>Orientation</ogc:PropertyName>
    <ogc:Literal>200</ogc:Literal>
</ogc:Mul> 

for sine I am not sure what function is, but it doesn't work when only multiplication is used. This is needed because when adding hatches to objects, there is need to draw a hatch with angle of 45 to one side of object. Something like this, but when object is rotated by some angle.

goal

6

You can do math in SLD in most places, but a WellKnownMark element is not one of them.

This is what the standard says, GeoServer has a custom extension allowing to stick a CQL expression in the middle of a mark name like this:

wkt://LINESTRING(0 0, ${Orientation * 200} 33)

I could not try it out, but it should work.

  • It works, solution that I am now using to achieve this is wkt://LINESTRING(0 0, ${sin(Orientation) * 200} ${cos(Orientation) * 200}) If somebody need it – Zoran Kokeza Mar 4 '17 at 15:48

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.