1

From a point geometry layer, I'm using an expression with buffer function as shown in the screenshot below:

enter image description here

I would like to add two more expressions to this point geometry layer:

  1. An expression for Symbology to draw the radius line
  2. An expression for Labels to add the length value of the radius

The expression that creates the buffer is as follows:

buffer(
    $geometry,
    array_mean(  -- lengths mean
        array_foreach(
            overlay_nearest( -- get nearest points
                'POINT_LAYER',
                $geometry,
                limit:=4
            ),
            length(
                make_line(
                    $geometry,
                    @element
                )
            )
        )
    )   
)

I show a screenshot with the expected result:

enter image description here

3
  • 1
    So you seem to know, how to generate geometries using expression. What is keeping you from using make_line()?
    – Erik
    Apr 6 at 7:14
  • I have made an approximation with this expression but I think it is not the correct solution. I think the hard part is to get a line to the edge of the buffer: shortest_line ( collect_geometries ( overlay_nearest( -- get nearest points 'BUFFER', $geometry, --max_distance:=1000, limit:=4 ) ), $geometry )
    – Acperience
    Apr 6 at 7:41
  • The result that appears in the screen capture of the expected result is a hand-drawn simulation. It is not the application of the shortest line function.
    – Acperience
    Apr 6 at 7:44

1 Answer 1

4

For the radial line (a Geometry Generator symbol layer):

with_variable(
    'buffer_dist',           -- store result of distance calculation as a variable
    array_mean( -- lengths mean 
        array_foreach( 
            overlay_nearest( -- get nearest points 
                @layer, 
                $geometry, 
                limit:=4 
            ), 
            length( 
                make_line( 
                    $geometry, @element 
                ) 
            ) 
        )
    ),
        
    make_line(
        $geometry,
        project(
            $geometry,
            @buffer_dist,   -- insert the calculated value as a variable
            radians(270)
        )
    )
)

For the label position (Geometry Generator placement):

with_variable(
    'buffer_dist',
    array_mean( -- lengths mean 
        array_foreach( 
            overlay_nearest( -- get nearest points 
                @layer, 
                $geometry, 
                limit:=4 
            ), 
            length( 
                make_line( 
                    $geometry, @element 
                ) 
            ) 
        )
    ),
        
    project(
        $geometry,
        @buffer_dist / 2,      
        radians(270)
    )
)

The label expression:

array_mean( -- lengths mean 
        array_foreach( 
            overlay_nearest( -- get nearest points 
                @layer, 
                $geometry, 
                limit:=4 
            ), 
            length( 
                make_line( 
                    $geometry, @element 
                ) 
            ) 
        )
    )

Result:

enter image description here

9
  • 1
    You have an attribute field that determines the buffer distance in the point layer?
    – Matt
    Apr 6 at 8:04
  • 1
    See update. I store the result of Kadir's expression as a variable and then use it to create the line and to position the label.
    – Matt
    Apr 6 at 8:26
  • 3
    Please include important information, like the fact the buffers are created 'on-the-fly', and the expression to do so, in your question, rather than added as comments. It's clearer when all the essential details are in one place.
    – Matt
    Apr 6 at 8:32
  • 1
    A point has no extent, hence 0 bounds @Acperience
    – Erik
    Apr 6 at 8:50
  • 1
    No, hence I removed it from my answer. The label expression is essentially the expression of Kadir, without the buffering part. I have added it above.
    – Matt
    Apr 6 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.