3

QGIS 2.18.3:

I have a shapefile layer in QGIS which describes points. One class of points are ship lane beacon lights (svg image), and these should be turned towards the ship lane. The angle of the ship lanes are found in another layer (the shapefile line layer for the ship lanes) and the angle is in degrees with decimals (for instance 248.8000 ie 248.8 degrees).

It is possible to edit the layout rule for the SVG symbol, and there I can edit the rotation calculation. But how do I tell QGIS to use a field "ANGLE" in another layer "Shiplane" for the rotation angle?

2

There is Plugin called "refFunctions", where you can reference to another layer.

Supposing I have a point layer with ship lights (plane symbol) and a linestring layer with the lanes:

enter image description here

In the layer Properties > Style of the ship layer you can use SVG Marker to choose your SVG Marker. Edit the rotation parameter with an expression:

degrees(azimuth(start_point( geom_from_wkt( geomnearest( 'lane', '$geometry'))), end_point( geom_from_wkt( geomnearest( 'lane', '$geometry')))))

The refFunction geomnearest looks for the nearest lane from the ship. This returns the lane as an WKT string. geom_from_wkt converts this to a line geometry. With azimuth of start and endpoint you can calculate the angle, which will be used as the rotation value.

The problem is that the lines are not subdivided in segments. See the rotation of the upper right symbol. To solve this you can use the explode lines tool in QGIS (Processing>Toolbox>type explode in search field).

One linestring with nodes: enter image description here

Exploded line: enter image description here

5
  • the refFunctions calculator inserts a Reference expression group in the field calculator, but I am too much of a newbie with QGIS to understand how to use this. So I have the layer with buoy lights and another layer whish contains among others a column with angles for the navigational lines that intersect the buoy lights. I should somehow get the field calculator to find navigational lines that intersect buoy lights, get the angles for the lines, and write them as a new column to the buoy lights layer? – Benjamin Donner Feb 24 '17 at 14:32
  • - I have the angle that should be used as degree numbers in the field "ANGLE" in the layer "Shiplane" - I have the light SVG symbol that I need to rotate in the layer "LIGHT" So no calculation should be needed, I only need to know how I enter the rotate function for the SVG symbol so that it takes the angle number from the ANGLE field in the other (Shiplane) layer – Benjamin Donner Feb 24 '17 at 15:21
  • OK easier than I ever imagined it seems: I tried to in the SVG symbol rotation use a geomnearest ('shiplane','angle') and it seems to work, in theory. The next problem arose immediately, however. The light line angle is in some instances 180 degrees wrong. Is there a way to find out in which way the line is longer, and turn the angle number 180 degrees around if the line is longer in the opposite directon than the original angle (because the line always starts from the lights)? – Benjamin Donner Feb 24 '17 at 15:59
  • It sounds like the lines have different start and endpoints each. – Stefan Feb 24 '17 at 20:15
  • How is the angle calculated in the layer lane? Did you tried to get the angle directly from the lane geometry? Ther should only be the problem with start and end point, then. – Stefan Feb 27 '17 at 9:31

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.