3

How do I show arrowheads at the ends of a polyline (not at each segment) using QGIS?

I know I can uncheck Repeat arrows at each segment, but that curves the line, which generally isn't what I want to see (and if I have a label on that line, the label stays with the line as digitized, not following the curve). If I then uncheck Curved arrows, the line becomes a straight line from end to end of the polyline (but the label stays with the line as digitized).

0
6

You can create an arrow on the last x % of the line.

On the line style, use a simple line for the whole line, then add a geometry generator to extract the last 5% (or whatever suits your need), which can then be styled as an arrow.

The expression would be:

line_substring( 
   $geometry, 
   length($geometry)*.95,
   length($geometry))

The last step would be to use a similar style between the simple line and the arrow so the two merge smoothly

enter image description here

Another option if you need a simple arrow head is to add a marker line, on the last vertex only, with a rotated triangle marker.

enter image description here

1
  • A variant to the solution by @JGH : to get the last segment (instead of the last x% of the line) use this expression: make_line (point_n( geometry(get_feature_by_id (@layer, $id)), -2), point_n( geometry(get_feature_by_id (@layer, $id)), -1))
    – Babel
    Aug 19 '21 at 19:16
4

Add an arrow-symbol on the end-point of the line:

  1. Add a Symbol layer / Geoemtry Generator / Point with this expression: end_point ($geometry) (screenshot 1)

  2. As marker for this symbol-layer point, add a triangle.

  3. Use a data driven rotation with this expression (screenshot 2):

    degrees (azimuth (
      point_n( geometry(get_feature_by_id (@layer, $id)), -2),
      point_n( geometry(get_feature_by_id (@layer, $id)), -1)))
    

Screenshot 1:

enter image description here

Screenshot 2: enter image description here

1
  • Thank you, JHG, for reminding me of what I have done in the past but somehow forgot about. Your second option is the one, with a marker at each end of the line, so three symbol layers: line, arrow left (marker line), and arrow right (marker line). Unfortunately, I don't see anything in the way of modifying arrow length and width, or adding my own symbols here, but I'll look some more to see if I missed something.
    – bkepl
    Aug 25 '21 at 14:42

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.