[GIS] Showing only point markers when labels are shown in QGIS

qgisrulestyle

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

Best Answer

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)

Related Question