You can use a setting that only shows labels of there are no other features nearby: nearest neighbor must have a minimal distance and only if that condition is fulfilles, a label will be placed.
You can make the settings in the tab placement
: set Priority
to low, Obstacle Settings
(bottom right) to high and use the Symbol ε
for a data defined override with the following expression. Change 250
at the bottom to a value that fits your data: it is the distance each point has to its closest neighbour. If this value is smaller than the value you set, placing labels is avoided. The overlay_nearest
function is available in QGIS 3.16 +:
length (
make_line (
$geometry,
array_first (
overlay_nearest(
@layer,
$geometry
)
)
)
) < 250
The expression measures the distance of each point to it's next neighbour. If it is lower than the threshold defined (250 meters in my case), then these features are set to true
and in this way generate a data driven value for the setting that says:
When activated, features acting as obstacles discourage labels and
diagrams from covering them.
You have further options to reduce labels based on data driven override: in the tab Rendering
set a data driven override for Show Labels
: I used the same expression as above, just changed the last line to ) > 400
(remark the changed symbol >
as well!):
There are a lot of other options how to control how and where labels appear (see e.g. here). You could use Rule based labels and define different rules for areas with low and high density of features: using similar filters as here or creating a new attribute for several areas of different label density etc.
It depends very much what exactly you want to achieve. You should define a list of criteria to be fulfilled. Based on that, a more precise answer for your very use case is possible.