3

Related to the question line below. How do I make the arrow point to the line correctly ?

This code did not work :

with_variable('myvalue',line_interpolate_angle(geometry:=intersection(buffer(geometry:=$geometry, distance:=50, segments:=3),overlay_nearest(layer:='railways', expression:=$geometry)[0]), distance:=50),if(@myvalue < 180,@myvalue+90,@myvalue-90))

Rotating point layer according to line layer in QGIS

enter image description here

winnewoerp
  • 1,504
  • 11
  • 21
Er Re
  • 103
  • 4

1 Answers1

4

For the rotation of the arrow marker, use this expression on the point layer and replace line in line 4 with the name of the line layer.

Explanation: for each point, calculate the azimuth (angle) with the function azimuth() from the initial point ($geometry) to the closest point on the line (to get the line: use overlay_nearest()) with the function closest_point(). Convert radians to degrees with degrees().

degrees(
    azimuth(
        $geometry,
        closest_point( overlay_nearest ( 'line', $geometry)[0],
        $geometry
        )
    )
)

Dotted line for visualization purpose only: enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208