7

I am attempting to recreate a layout from ArcGIS in QGIS. One of the advanced label options in ArcGIS is to force horizontal labels outside a polygon. You can optionally choose which quadrant the labels fall in.
Horizontal label outside polygon - ArcGIS

This question is related, but the labels are parallel with the polygon perimeter: Labels outside polygons in ArcMap

The answer to this question is basically what I'm looking for, but my polygons aren't circles: Upright/Horizontal labels when labeling polygons at perimeter in QGIS That question was asked in 2014, so perhaps a solution has been found in ensuing years? I am fine with prioritizing a quadrant for location, if that would help.

5 Answers 5

6

Facing a similar issue, I applied in Placemente/Data Defined the following expressions:

For X coordinate:

x( closest_point( $geometry, make_point(  x_max($geometry),(  y_min( $geometry )))))+20

For Y coordinate:

y( closest_point( $geometry, make_point(  x_max($geometry),(  y_min( $geometry )))))-15

In this case, the label is at the bottom right of the polygon. The constants (+20 and -15) can be adapted depending on the scale, but it works for all features automatically

5

I'm using QGIS 2.18.4

You can create a virtual layer importing your polygons by a buffer distance (and keeping your label field):

enter image description here

And then label like this:

enter image description here

You will end up with this (I'm adding the buffer outline so you can see it but you can set it to transparent):

enter image description here

4

Unfortunately, there is no automatic way to place the labels outside the polygons and keep them horizontally. After several tests, I found two ways to do that, but both of them are time consuming:

  1. Using Rule based Labeling

    • You to define each label individually, and use Placement -> Data Defined -> Coordinate X and enter the following formula:

      x(bounds($geometry))+ Constant
      

      Placement -> Data Defined -> Coordinate y and enter the following formula:

      y(bounds($geometry))+ Constant
      

      Where constant is an offset value to shift the label outside the polygon, thus, you need to adjust the constant for each individual label.

    • I used Alignment horizontal and vertical and wrote 'Center'and 'Cap', respectively.

enter image description here

Here is the result:

enter image description here

  1. The second option is to add x and y fields in the attribute table, then go to Placement -> Data Defined -> Coordinate X and Coordinate y, and select x field and y field, respectively. Then start editing and move the labels manually outside each polygon.

As I said at the top of my answers, both solutions are not efficient. But I hope the developer team can add this option in the next releases.

3
  • This is the same as in the first answer I referenced. I do not want to follow the curvature, but to have the labels horizontal, as similar to the 2nd link I referenced. That answer doesn't work though because my polygons are not circles. Commented Mar 30, 2017 at 3:19
  • I misunderstood your question, I thought you want the labels to follow the curvature of the polygon.
    – ahmadhanb
    Commented Mar 30, 2017 at 3:35
  • I updated my answer.
    – ahmadhanb
    Commented Apr 3, 2017 at 6:01
3

If I understand correctly, you can do like this:

enter image description here

Keep in mind that using curved labels will not show up too long laybels.

2

This is an answer to an old question, but placement of labels outside polygons will become a standard option in QGIS 3.14 per PR #36106

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.