5

I have a polygon layer with a number as label. Now I want that my labeling is always in the left upper corner of the single polygon, like in the screenshot.The red rectangle is the position, where the label should be placed

enter image description here

If I zoom in the should be visible and placed like in the second screenshot.

enter image description here

If such a labeling is possible, how can I create that?

I tried the labeling tab of the gui, but it doesn´t work pretty well With my settings the labels of other polygons where placed in their visible neighbours

enter image description here

1

2 Answers 2

6

To get that result in QGIS 3.14:

  • Check the 'Geometry generator' option inside the labels options and add make_point(x_min( $geometry), y_max( $geometry)) in the expression box
  • Select 'Offset from point' placement
  • Select the bottom right Placement Quadrant
  • Adjust the 'Offset X,Y' settings to move the label a little away from the corner if necessary

enter image description here

An alternative method for older QGIS versions:

  • Duplicate your layer (we'll use one layer for the grid and another for the labels)
  • Select 'Single Symbol' styling
  • Select 'Geometry Generator' as 'Symbol layer type'
  • Select 'Point/Multipoint' as 'Geometry type'
  • Add make_point(x_min( $geometry), y_max( $geometry)) in the expression box
  • Change the 'Symbol layer type' under 'Geometry Generator' from 'Simple marker' to 'Font marker'.
  • Set the 'Anchor point' to 'top left'
  • Click on the 'Data defined overide' button next to the 'Character' box and select 'Edit'.
  • In the window that pops up type in the field name (between double quotes) you want to use to label.
  • Click OK
  • Adjust the 'Offset X,Y' settings to move the label a little away from the corner if necessary

enter image description here

enter image description here

enter image description here

enter image description here

2
  • Thank you very much for your help. Then we have to update our QGIS version in the company. Now we use QGIS 3.4.8 LTR. In this version I don´t find the geometry generator in the placement tab
    – joe_gerner
    Commented Jul 23, 2020 at 9:12
  • 1
    I've added an alternative for older QGIS versions, that even works in QGIS 2.18. Commented Jul 23, 2020 at 9:48
4

To completely answer the question we need to extend the answer of Michel by adding a label to any grid squares cut off by the top and left hand edges of the canvas. This can be done by updating the geometry expression to:

make_point(x_min(intersection(@map_extent, $geometry)), y_max( intersection(@map_extent, $geometry)))

enter image description here

1
  • Could I force the labeling into the associated polygon? If I zoom in, some labels of cut off polygons appear in other polygons.
    – joe_gerner
    Commented Jul 27, 2020 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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