1

In QGIS I can label a polygon in different ways (Figure 01). But how could I put several labels distributed inside a single complex polygon (Figure 02)?

Figura 01

Figura 0

Denilson
  • 695
  • 4
  • 12

4 Answers4

2

I don't believe there is currently a tool that does what you're asking- however, there are a couple of ways you could go about getting the same output. One way would be to create a new vector layer- and using the digitizing toolbar go to the "Add Feature" tool (Should look like 3 red dots being connected) and add points where you would want the label to appear. Assign the label as a column in each of the points attribute tables (or use the join attributes by location tool) and in the layer properties turn on labels, and choose the label you created earlier. Another way I could think about doing it by separating the polygon itself using the "Split Features" tool and similarly, turn on labels.

mimiasmith
  • 73
  • 4
  • Boa solução, enquanto não for incluído no QGIS a opção de copiar label (similar a opção de mover label). Criar uma camada de pontos, criar uma camada virtual fazendo o spatial join (st_contains) por localização entre ambas as camadas, e aplicar o label resolverá o problema. Dividir a camada de polígono eu não acho bom pois altera os dados originais. – Denilson Jun 29 '21 at 16:34
1

You can use rule-based labels, define a label and than copy/paste it. If you're lucky, QGIS places the labels in different parts of the polygon automatically - that's what happened with labels 1 and 2 in my screenshot. Label 4, however, was placed beneath label 1.

To shift it to another location, in the placement tab activate Geometry generator. Like this, you can defined a place for custom placement of the label. Right-click on the map canvas where the label should go, copy the coordinates (available since QGIS 3.16) and paste these coordinates as shown in the screenshot with this expression: make_point([x-coord],[y-coord]).

enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208
  • Boa ideia, mas seria complicado fazer isso para centenas de polígonos complexos, similar ao exemplo que eu apresentei na figura. – Denilson Jun 29 '21 at 16:28
  • Yes, automatic placement would be nice - maybe you can create an expression with geometry generator. However, I would not know of any approach to realize this. Labeling, especially in such highly complex contexts, remains to a certain degree manual work. By the way: as this is an english-language site, please post your messages in english. – Babel Jun 29 '21 at 16:45
  • Just as an idea: you could create a rectangular grid (define an appropriate site) and group together contiguos rectangles that are fully inside of each polygon. For each group of a certain size (define a threshold, like: a group consist of at least 5x5 cells), create the centroid and place a label there. Changing grid-size and threshold, you can play around different placement-settings. – Babel Jun 29 '21 at 16:50
1

There is an automatic way to set several labels to each "major" part that is separated of the rest of the polygon by a narrow "bridge".

The idea is to create a grid and there make a circle in the centroid of each grid-cell. Set the radius to a size slightly bigger than the width of the "land bridge" connecting several major parts. Now check for each cell if it's circle is overlapping completely with the polygon: only these cell should be kept. Based on this, you split the polygon in several smaller polygons that correspond to the major "branches" of the initial polygon. Now label this resulting polygons.

Screenshot, visualizing the solution: original polygon (orange), blue cells: those with a circle that falls completely inside of the original polygon for a custom-defined radius. Each of the (dissolved) blue polygons is now labeled (disalbe visibility of grid and blue polygons, only keep labels): enter image description here

To select the grid-cells, I used this expression with Geometry by expression on the polygon-layer. Replace grid by the name of the grid-layer and adapt the size of the radius in line 9 (here: 200):

collect_geometries(
    array_foreach(
    overlay_contains(
        'grid', 
        $geometry
    ),
    if (
        within (
            make_circle(centroid (@element),200),
            $geometry
        ),
        @element,
        buffer (make_point (0,0),1)
)))

Adapt the radius to get the optimal number and shapes of polygons. Use Geometry generator to interacitvely control the output; when satisfied, copy the expression to Geometry by expression.

When done, dissolve the resulting polygons, convert from multi- to single parts, delete polygons smaller than a certain area (to get rid of small, isolated cells). Than set a label to the centroid of the polygon and set the rendering style of the symbology to No Symbols to keep only the label:

https://i.stack.imgur.com/rdEGg.png

Babel
  • 71,072
  • 14
  • 78
  • 208
1
  1. Create a negative buffer of the polygon with such a (negative) buffer distance that the polygon is "cut" in several parts at narrow locations so that the tiny branches connecting the different "main" parts become disconnected. The resulting polygons are shown in the screenshot with the dotted line.

    Use Geometry by expression with this expression buffer ($geometry, -10) and adapt buffer-distance (here: -10) to your needs.

  2. Than label each polygon and set the rendering of the symbol to No symbols to keep only the label.

enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208