I have a QGIS project in which I work with a polygon layer ('POLIGONS_TEST') and a point layer ('PUNTS_TEST').
I use the following Geometry Generator expression on the 'POLIGONS_TEST' layer to draw a line that joins the centroid of each polygon with the nearest points layer 'PUNTS_TEST'.
make_line(
centroid($geometry),
closest_point(
overlay_nearest('PUNTS_TEST', $geometry,limit:=1)[0],
$geometry
)
)
As you can see in the screenshot, the result is correct but there is but there is a visual inconsistency. The closest_point function returns the closest point from geometry1 to geometry2. It seems that it considers geometry1 as the polygon's boundary and not as the centroid.
How could I solve this so that the proximity is calculated concerning the centroid, without having to convert the polygon layer to a point layer?
Unsatisfactory result after applying the expression proposed by the users @Erik and @Andrea:
closest_point
geometry function. What I am looking for is some solution to consider the centroid as the reference point and not the boundary. Regarding the screenshot, the gray lines are the result of the expression. The red lines is an indicator to say that it is not the expected result. And the blue lines are the expected result.