4

I have a table with field calculated by function:

   NEW."rotationAngle" := degrees(
                         ST_Azimuth(
                            ST_StartPoint(NEW.the_geom)
                          , ST_EndPoint(NEW.the_geom)
                         )
                      ) - 90;

Now i publish this table as Geoserver layer and set style with Roataion tag:

  <Rule>        
    <TextSymbolizer>
      <Geometry>
        <ogc:Function name="startPoint">
          <ogc:PropertyName>the_geom</ogc:PropertyName>
        </ogc:Function>
      </Geometry>
      <Label>
        <ogc:PropertyName>annotation</ogc:PropertyName>
      </Label>
      <LabelPlacement>
       <PointPlacement>
         <Rotation>
          <ogc:PropertyName>rotationAngle</ogc:PropertyName>
         </Rotation>
       </PointPlacement>
      </LabelPlacement>
      <Fill>
        <CssParameter name="fill">#FFFFFF</CssParameter>
      </Fill>
      <VendorOption name="spaceAround">10</VendorOption>
      <VendorOption name="autoWrap">85</VendorOption>
      <VendorOption name="group">yes</VendorOption>
    </TextSymbolizer>
    <LineSymbolizer>
      <Stroke>
        <CssParameter name="stroke">#000000</CssParameter>
      </Stroke>
    </LineSymbolizer>
  </Rule>

And result:

enter image description here

How can you see label angle not equals line angle.
When i publish table as a SQL view:

SELECT gid, annotation,"fontSize", the_geom, degrees( ST_Azimuth( ST_StartPoint(the_geom), ST_EndPoint(the_geom) ) )-90 as angle from annotations

With same style i get result:

enter image description here

Label angle equals line angle.
Why it's hepping? What i do wrong in first case?

UPDATE

I checked angle values in both cases and they are same.
Table's geometry have a custom projection. When i publish it on Geoserver i reproject it in EPSG:4326.

Update

I changed function to:

   NEW."rotationAngle" := degrees(
                         ST_Azimuth(
                            ST_Transform(ST_StartPoint(NEW.the_geom),4326)
                          , ST_Transform(ST_EndPoint(NEW.the_geom),4326)
                         )
                      ) - 90;

But not help.

Update I found interesting behivor. I setted Label text as rotationAngle property and open both layers in Layers Preview and results:

View Layer:

enter image description here

Table Layer:

enter image description here

Table Layer in application (map projection EPSG:900913):

enter image description here

Just wft going on?

Solved

Of couse it was stupid. My application's map showed in EPSG:900913. So why i calculate rotationAngle in EPSG:4326? I dont know. This is correct function:

       NEW."rotationAngle" := degrees(
                         ST_Azimuth(
                            ST_Transform(ST_StartPoint(NEW.the_geom),900913)
                          , ST_Transform(ST_EndPoint(NEW.the_geom),900913)
                         )
                      ) - 90;
  • 1
    Have you checked that the values in the table and those returned by the query in the SQL View are the same? Do you work in the native projection all the time so that your function does not compute the angle in another projection than the output is? Next step could be to make a reproducible test case. Import for example the tasmania_roads.shp demo data from the data_dir into PostGIS, create rotationAngle field and populate it create SLD and verify the error. If you can reproduce, publish your SLD so that people interested in helping you can do it as easily as possible. – user30184 Aug 17 '14 at 10:02
  • @user30184 there are much of question. I add new answers in my question. – Kliver Max Aug 17 '14 at 10:25
  • 1
    I suppose that when you compute the angle with your function it will be the angle in your custom projection. Because you store it as stable attribute the angle will not be changed to suit the output projection. Two tests: 1) Look if label angle is OK with your current rotationAngle if you use your custom SRS also as outputprojection for Geoserver 2) Change your function to use ST_Transform(ST_StartPoint(the_geom),4326) and similarly for EndPoint for computing the EPSG:4326 rotationAngle into your table. – user30184 Aug 17 '14 at 10:49
  • You must turn the Geoserver logging into Geotools developer level and look at the logs before you can say if your function and the SQL query that Geoserver creates yield the same result. I believe that Geoserver is adding some parameters to the SQL View query automatically. – user30184 Aug 17 '14 at 15:02
  • I suggested to translate into EPSG:4326 because you wrote earlier "When i publish it on Geoserver i reproject it in EPSG:4326". Good that your problem is solved now. – user30184 Aug 17 '14 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.