QGIS – How to Create Variable Buffers with Nearest Mean Distance Radius

bufferexpressionproximityqgis

Given a point geometries collection, I would like to use an expression which:

  1. Find the 4 points nearest to each other
  2. Create the buffer for each group of 4 points with the radius distance value corresponding to mean distance to the 4 nearest points.

I add a screenshot representing the expected result:

enter image description here

Best Answer

You can use this expression:

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

enter image description here