10

Is there a chance to define a QGIS style rule to just show point markers when their label is shown?

My aim is to exclude all points which are not labeled because of collision between labels.

Example:

how to switch points invisible when their labels collapse

5
  • Can you provide some screen shots of your attribute table and current points displayed on map?
    – whyzar
    Nov 8, 2016 at 18:01
  • @whyzar Example picture is uploaded
    – Jakob
    Nov 9, 2016 at 6:58
  • 2
    The collision may also be reduced, if you set the option "Discourage Labels from Covering Features" at Rendering tab.
    – MartinMap
    Nov 9, 2016 at 8:44
  • I don't think this can be done. Nothing in the API either to check if a label is visible: qgis.org/api/classQgsLabel.html Nov 9, 2016 at 14:14
  • Another question has been asked that covers the need/desire to detect which features are labeled or not. Any useful answers to that may well give someone a new angle to approach this one.
    – Phil G
    Nov 21, 2016 at 14:53

4 Answers 4

3

This is not ideal, but if you are OK with the label always appearing on the marker, you can use a background on your label as a workaround.

  1. Go to Layer Properties, and under Style choose "No symbols" (yes, you read that right).
  2. Under Labels, choose Background from the sub-menu (looks like an Interstate highway symbol). I typically use an SVG, but a circle may work fine for what you want.
  3. In the Background sub-menu, decide on your Size Type: Buffer or Fixed. With Buffer, the symbol will enlarge until it is big enough to encompass all text, so I expect you will want fixed. The example below uses buffer.
  4. At the top of the Labels section, choose the field you want to label with, or enter an expression.
  5. Make sure the Placement is not offset.

Downsides:

  1. Complicates having the symbol show in a legend in a print composer (there are workarounds by creating another layer and referencing it in table of contents, before turning off and locking layers)
  2. Text is centered on the symbol. You can concatenate spaces to the front of the label to shift it right, but then more other labels are obscured and don't show. You don't get an option to move labels around points for least amount of conflict.
  3. You lose a lot of functionality in formatting symbols, such as color scales.
  4. It seems that label conflicts sometimes need to be more severe to hide the label - mine sometimes overlap without some finagling. This may be a result of using buffer size type.

An example that takes a file name from "field_1" and removes the .jpg extension to form label text for photo locations:

settings

The results:

zoomed in: zoomed in and zoomed out: zoomed out

(note - the direction the svg icon points was set by an expression referencing another field in the table)

0

have you had a look at Nyall Dawson's excellent tutorial at http://nyalldawson.net/2015/07/recent-labelling-improvements-in-qgis-master/

In the third segment of his tutorial, he discusses creating an obstacle layer. This may assist you.

-3

Set a rule (rule-Based styling) to your symbol:

"label" IS NOT NULL

(assuming, your field for labels is named "label")

Now symbols will be shown, if the field for labels is not empty.

2
  • 2
    I don't think that is what OP is asking. The values in label wont be null, they are just not being shown because they overlap with other labels. Nov 9, 2016 at 12:05
  • @Vesanto Yes, the values aren't NULL.
    – Jakob
    Nov 9, 2016 at 13:05
-3

Just select all values that have a label using a query, export to new layer than use the newly created layer.

3
  • Can you give me a short query example for selecting values which currently show a label?
    – Jakob
    Nov 9, 2016 at 13:30
  • Sure provide a screenshot of the attribute table you're working with and which fields have the labels you want in it.
    – NULL.Dude
    Nov 9, 2016 at 13:52
  • I just realised this is for QGIS I work mainly with ArcGIS but in theory the process should be the same, to select all data associated with the values that have the labels, then create new layer with those selected values.
    – NULL.Dude
    Nov 9, 2016 at 14:04

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.