1

I am using the style editor in GeoServer to make some symbols for an OpenLayers based Web GIS solution. But I face a challenge when trying to rotate some symbols. I have a Point Layer that needs to be rotated based on the values in a field named "ROTATION".

This is fairly simple and I created the following SLD that do this:

enter image description here

But unfortunately the values in the rotation field is not providing the correct rotation (it might be radians or something)... so I get the following result in my Web GIS (it is the small black lines):

enter image description here

I wish the black lines to be perpendicular to the red and blue lines. I have calculated that I will get the right rotation using the formula: (360 - "ROTATION" + 90) / 360

At least it works when I calculate a new field on the feature class using MSSQL (where the layer is currently stored). Unfortunately I can't do the trick in MSSQL as the data are currently in production. So my question is - how do I get this formula to work on the field ROTATION in the SLD editor.

I am using GeoServer 2.10.

I have so far read that I might need something with "ogc:Literal"Formula"/ogc:Literal", but what should I write exactly.

6

Something like this should work, using the math operators - please note it is untested:

<Rotation>
    <ogc:Div>
        <ogc:Sub>
            <ogc:Literal>450</ogc:Literal>
            <ogc:PropertyName>ROTATION</ogc:PropertyName>
        </ogc:Sub>
        <ogc:Literal>360</ogc:Literal>
    </ogc:Div>
</Rotation>
  • Thanks JimT. I tried your suggestion but when I insert your code my symbols go back to looking as if there has been no rotation set at all. Is it possible that I have to set some initial parameter in the start of the SLD script to make it work with the math operators? Or do you have other suggestions? I changed the lines with Rotation to se:Rotation to fit with the other parts of my script. And when I hit "Validate" it says "No validation errors" – Kristian Birchvald Jensen Jan 18 '17 at 12:27
  • If your rotation values are in degrees then dividing by 360 as per your above equation is going to result in a tiny rotation that is impossible to see. Can you confirm the maths? Note that angles are expected in degrees – JimT Jan 18 '17 at 13:39
  • I can confirm the math. No matter what values I put into the Literal boxes nothing happens. I get my (wrong) rotation shown above, when I have no literal statements, but as soon as I add these (no matter the values eg 360 or 2) my black lines go back to a symbol showing no rotation. – Kristian Birchvald Jensen Jan 18 '17 at 13:45
  • I have tested the code and the basic functionality works - point objects are rotated. If the Rotation field is in degrees then I'm afraid the maths remains suspect. What I do suggest is that you start basic build up from there to try and track where the error is. Start with this perhaps: <se:Rotation> <ogc:Literal>45</ogc:Literal> </se:Rotation> – JimT Jan 18 '17 at 14:10
  • 1
    Hi JimT. Of course you were right. I did some trial and error and thanks to you made it work with: <se:Rotation> <ogc:Div> <ogc:Sub> <ogc:Literal>450</ogc:Literal> <ogc:PropertyName>ROTATION</ogc:PropertyName> </ogc:Sub> <ogc:Literal>1</ogc:Literal> </ogc:Div> </se:Rotation> ... Apparently my math skills could need a fresh up ;) Thanks again! – Kristian Birchvald Jensen Jan 18 '17 at 14:15

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.