6

I have a set of layers, one of them is labeled using geometry generator. Thing is, at some scales (1:800 and up) and some features (like 1/30) the geometry generator evalues to null geometry, so the feature is not labeled. I "fixed" it temporarily evaluating the resulting geometry and using another tye of label if it is null, but its not acceptable for printing. The Geometry Generator expression is

with_variable(
    'g',
    difference( 
        buffer($geometry,12),
        aggregate(
            layer:='ManzanasM',
            aggregate:='collect',
            expression:=$geometry)),
    if(buffer( @g,-5) is null,
        buffer(pole_of_inaccessibility($geometry,1),5),
        buffer( @g,-5)))

It makes a buffer of itself and then a difference between that buffer and the layer 'ManzanasM', so the resulting polygon is outside the block. Its a grose replacement of a "label outside polygon" feature that I know its now implemented, but I cannot install new QGis in my PC without a lot of bureaucracy.

The layer is part of an Atlas dependant layout, I dont know if that's affecting it, but I dont think so. Used the same expression in Symbology to visualize exactly what im labeling, and after I zoom out more than 1:800 the geometry dissapears (and is replaced by a circle, because that's my temporary solution).

In the image, its visible how the colored parts outside the blocks are the zones where i want my label to be. There are two geometries that are not correctly created in the lower left.

Example

EDIT: Here are some example files. They need those custom expressions loaded.
https://drive.google.com/file/d/1XFJVQZfrADX92tnEe0Lz-k3AC9EGDFGA/view?usp=sharing

Centered labels instead of outside polygon

9
  • 1
    Geometry generator only renders expression-generated geometries when the geometry of the current feature ($geometry) is visible. Thus if you have apoint layer and create a line from this point with geometry generator, the line disappears as soon as the point falls out of the map canvas, even if the line would continue to run over the canvas. Could somthing similar be the problem in your case?
    – Babel
    Mar 18, 2021 at 14:09
  • Do the features where the label is not created correctly have geometry errors? I guess in your screenshot you speak about the block labeled 56 and 64 that are not correct, right? Can you provide sample data to test?
    – Babel
    Mar 18, 2021 at 14:17
  • 1
    No, all features are visible. And this layer is virtual, generated on the fly. You made me think maybe thats an issue, im going to save the virtual layer and apply this style to it
    – Opazo
    Mar 18, 2021 at 15:00
  • I'm curious to hear if the virtual layer was the issue.
    – Babel
    Mar 18, 2021 at 15:02
  • No it wasn't... Added sample files. Most expressions are not required but im not in mood for cherry picking... sorry :(
    – Opazo
    Mar 18, 2021 at 15:19

0