1

This question already has an answer here:

I am working on a road layer containing hundreds of roads and want to print it out in a A2 size with all labels. I want the labels to be fixed in the original position and not depend on scaling of the map. Is there a solution?

marked as duplicate by whyzar, JGH, HDunn, Fran Raga, Erik Mar 28 at 13:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Welcome to GIS.SE, Kai. Please refrain from asking two questions at once, since answering and finding the correct answer (especially for others seeking the same solution) will be harder. – Erik Mar 27 at 7:55
3

Data-defined label placement

enter image description here

To position the labels at the centroid of the line, use these expressions

  • X coordinate: x(centroid($geometry))

  • Y coordinate: y(centroid($geometry))

To position the labels at the midpoint of the line, use these expressions:

  • X coordinate: x(line_interpolate_point( $geometry, distance_to_vertex($geometry, num_points($geometry)-1)/2))
  • Y coordinate: y(line_interpolate_point( $geometry, distance_to_vertex($geometry, num_points($geometry)-1)/2))

You can write different expressions to adjust the label position how you like.


Data-defined label orientation

Unfortunately, using data-defined label placement overrides the label orientation setting. The labels will revert to horizontal placement, regardless of what orientation setting (parallel/curved/horizontal) you choose.

enter image description here

So if you want the label oriented any way other than horizontal, you have to write another expression to control the label orientation. This expression will give you labels that are parallel to the midpoint of the line. (Use it with the expressions for placing labels at the midpoints.)

line_interpolate_angle( $geometry, distance(  start_point( $geometry),line_interpolate_point( $geometry, distance_to_vertex($geometry, num_points($geometry)-1)/2)))-90

enter image description here

As you can see it's not 100% perfect.


Bonus Tip: If you want the labels to always be the same size relative to the other items on the map, define the font size in map units.

enter image description here

  • Based on your solution, how to parallel labels to roads features using expression? – Kai Mar 28 at 5:44
-2

I suggest adding text labels per centerline and not labeling the road layer. This is possible in ArcGIS and I am hoping it is possible in QGIS as well. You can then style and position the text however you prefer. But it is manual work and if the road is many it may not work.

Otherwise, convert the road segments to points and label the points and make them transparent.

Not the answer you're looking for? Browse other questions tagged or ask your own question.