1

When I attempt to move a multipart label, all of the labels except for the one I am moving disappear. For example, when I move the lower "2-C" label (Figure 1) the upper two "2-C" labels disappear from the display and map layout (Figure 2).

I have encountered a related, but different question that addresses single labels disappearing in QGIS 2, though not multipart labels in QGIS 3.

How can I manually move a label and preserve all of the corresponding multipart labels using QGIS 3.10?

Figure 1

enter image description here

Figure 2

enter image description here

2
  • What do you call multipart label, are these labels of multipolygon when you check the label all part ? – J.R May 14 '20 at 17:11
  • Yes, that is correct @J.R. – Aaron May 14 '20 at 17:36
3

If the multipart polygon layer does not have a field with unique ids, I will encountered the same issue.

The solution is to delete the auxiliary file that stores the x,y positions of the labels, then create an id field that stores a unique id for every polygon using field calculator with the expression "id"= $id, and save edits.

Now when you start moving the labels, select the id field as a unique field to store the position for every label. The following illustration will explain it more clearly.

enter image description here

I am labeling a multipolygon shapefile for your reference.

enter image description here

7
  • 1
    but is your example a multipart polygon if each geometry has its own record? I thought a multipart polygon is where you have one record with multiple polygon geometries. Then you can't have a separate id per part unless you split it to single parts – she_weeds May 15 '20 at 4:57
  • @she_weeds My polygon is multipolygon shapefile, please check the newly added image in my answer. The explanation is long, but it is best described by mgri in his answer to the question Understanding difference between Polygon and Multipolygon for shapefiles in QGIS? – ahmadhanb May 15 '20 at 5:15
  • I don't think that answers the question. Your layer may be a multipolygon shapefile, but it doesn't change the fact that the features you are editing have one and only one exterior boundary (part) per feature. They could have more, because the layer allows for multipolygon geometries, but these features don't. I am pretty sure OP's issue is with features that have multiple parts (i.e. more than one exterior boundary). – she_weeds May 15 '20 at 8:25
  • 1
    I appreciate the answer. I needed to convert multipart to singlepart and then follow your instructions. To generate the unique ID, I used @row_number (QGIS 3) rather than $id. – Aaron May 20 '20 at 6:09
  • 1
    @Aaron Great! I am glad the problem is solved. – ahmadhanb May 20 '20 at 6:20
1

I suspect what you are describing is the intended behaviour. The label position is determined by auxiliary storage which is joined to your features by an unique id field (when you first move a label you are prompted for this field).

As such the auxiliary fields can only store one label location for each feature, and doesn't have any way of setting multiple label locations for multi-part geometries at this stage.

The most straightforward option is to convert the polygon to single part types and use @ahmadhanb's approach to generate an unique id for each part (note: you can't try to do this in Virtual Layer and move the labels - because you can't create auxiliary storage for Virtual Layers)


If you absolutely want to retain multiple labels and are fine with

  • only being able to move one label, and
  • label locations for all other parts fixed by a geometry generator expression

Then you could use a rather convoluted and limited workaround:

  1. Set up your desired label style then duplicate your layer.

    One ('Movable') will have a single movable label and auxiliary storage for label location. The other ('Static') will have static labels.

  2. Make the Static layer invisible.

  3. Move a label in your Movable layer to generate the auxiliary storage for labels.
  4. In your Static layer, use the expression at the bottom of this answer in geometry generator under label placement, but replace the layer name and ID field and buffer amount as required.
  5. Now you can move your labels around in the Movable layer within the buffer amount set in step 4 and the Static label will not show for that part. All other labels will be fixed to each part's centroid.

See example below:

  • White dotted line = buffer amount
  • Green label = movable
  • White label = static (geometry generator)

enter image description here


The expression to use in geometry generator label placement:

collect_geometries(
    array_filter(
        array_foreach(
            array_foreach(
                generate_series(1,num_geometries($geometry)),
                geometry_n($geometry,@element)),
            CASE WHEN intersects(
                        make_point(
                            attribute(
                                get_feature('MOVABLE_LAYER_NAME',
                                            'ID_FIELD',
                                            "ID_FIELD"),
                                    'auxiliary_storage_labeling_positionx'),
                            attribute(
                                get_feature('MOVABLE_LAYER_NAME',
                                            'ID_FIELD',
                                            "ID_FIELD"),
                                    'auxiliary_storage_labeling_positiony')),
                        buffer(@element,0.05)) --change buffer as required
            THEN null 
            ELSE centroid(@element) 
            END),
        @element is not null))

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.