Skip to content

Add settings for controlling margin around labels, and preventing duplicate labels #61475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

nyalldawson
Copy link
Collaborator

@nyalldawson nyalldawson commented Apr 15, 2025

This PR adds two new settings for vector layer labels:

  1. A 'margin around labels' setting. This allows setting a margin around a layer's labels, which prevents all other labels from being placed closer than this margin distance to the layer's labels:

image

  1. Prevent duplicate labels. This improves the appearance of labels in situations like road networks, where things like dual carriageways, service roads, etc can result in many labels of the exact same text appearing close to each other. When active, removes any labels with the exact same text (case sensitive!) which are closer then this minimum distance. The setting applies across layers, so duplicate text from ANY layer will be considered:

image
image

Note that both settings require a build based on GEOS 3.10 or later.

TODO:

  • unit tests

Fixes #23154

As well as avoiding multiple re-calculation of this, caching ensures
that we ALWAYS return the same bounds, which is crucial when we need
to remove the position from a spatial index
into candidate spatial indexes

We need to use the expanded bounds for candidate conflicts, not
the actual label bounds. Otherwise rules like minimum distance
between labels won't work, as potential conflicts aren't getting
returned when searching the candidate spatial indexes.
Allows setting a margin around a layer's labels, which prevents
other labels from being placed closer than this margin distance
to the layer's labels.
Improves the appearance of labels in situations like road networks,
where things like dual carriageways, service roads, etc can result
in many labels of the exact same text appearing close to each other.

When active, removes any labels with the exact same text (case
sensitive!) which are closer then this minimum distance.

The setting applies across layers, so duplicate text from ANY
layer will be considered.
@nyalldawson nyalldawson added Requires Tests! Waiting on the submitter to add unit tests before eligible for merging Feature Labeling Related to QGIS map labeling Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels Apr 15, 2025
@qgis-bot
Copy link
Collaborator

@nyalldawson
This pull request has been tagged as requiring documentation.

A documentation ticket will be opened at https://github.com/qgis/QGIS-Documentation when this PR is merged.

Please update the description (not the comments) with helpful description and screenshot to help the work from documentors.
Also, any commit having [needs-doc] or [Needs Documentation] in will see its message pushed to the issue, so please be as verbose as you can.

Thank you!

@qgis-bot
Copy link
Collaborator

@nyalldawson

This pull request has been tagged for the changelog.

  • The description will be harvested so please provide a "nearly-ready" text for the final changelog
  • If possible, add a nice illustration of the feature. Only the first one in the description will be harvested (GIF accepted as well)
  • If you can, it's better to give credits to your sponsor, see below for different formats.

You can edit the description.

Format available for credits
  • Funded by NAME
  • Funded by URL
  • Funded by NAME URL
  • Sponsored by NAME
  • Sponsored by URL
  • Sponsored by NAME URL

Thank you!

@github-actions github-actions bot added this to the 3.44.0 milestone Apr 15, 2025
@nicogodet
Copy link
Member

It should fix #44538 too

Copy link

github-actions bot commented Apr 15, 2025

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit bb1bf93)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit bb1bf93)

Replace the widgets with a label stating "not available on this
QGIS installation"
@nyalldawson
Copy link
Collaborator Author

@nicogodet

It should fix #44538 too

I think before closing that we should have some mechanism in place to automatically set margins in the background based on the callout shape settings. I don't think users should have to manually set this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog Items that are queued to appear in the visual changelog - remove after harvesting Feature Labeling Related to QGIS map labeling Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. Requires Tests! Waiting on the submitter to add unit tests before eligible for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove duplicate adjacent labels
3 participants