# Drawing line to the centroid of the concave hull composed by the set of each group of points within the same polygon

I am using the following Geometry Generator expression with which, for each point geometry, I draw a line to the centroid of the polygon the point is within:

``````make_line (
\$geometry,
centroid (
array_first(
overlay_nearest(
'POLY',
\$geometry
)
)
)
)
``````

With the following result:

Instead of drawing the lines to the centroid of the polygon, I would like to draw the lines to the centroid of the concave hull around the points within the same polygon.

I've tried to manually recreate this goal I'm trying to do in the following image:

• "nearest feature polygon" is misleading - in fact, you mean the polygon the points are within, if I understood correctly? Commented May 20, 2023 at 21:03
• That is correct as you have understood it Commented May 20, 2023 at 21:07

The trick is to first collect the points within each polygon with the functions `collect()` and `overlay_within()`. Use this expression:

``````centroid (
concave_hull(
collect(
\$geometry,
group_by:=overlay_within('POLY',\$id)
),
0.4
))
``````

Red point created with the expression from above; red line: concave hull, created with the same expression, without the `centroid()` part:

To draw a line from the initial points to the centroid of the concave hull, simple add `make_line (\$geometry,` at the beginning of the expression and add a closing bracket `)` at the end of the expression, see:

• Is it possible to reutilize your expression by adding the function make_line to get the lines from each point to the centroid of the concave hull? Commented May 20, 2023 at 21:08
• See updated answer. Commented May 20, 2023 at 21:12