Calculate distance from centroid to border of polygon

I'm trying to measure the overall distribution of parks in a certain part of the city. For this, I have already retrieved a layer that consists of the park-polygons, and created a layer of hexagons, covering the entire area. Through the vector toolbox I have also retrieved the centroid of each hexagon.

Now, I would like to measure the distance between each centroid to the nearest park-polygon. Ideally, the distance would automatically be added as a new column in the attribute table.

Is there a comprehensible way to do this in QGIS?

• EDIT: I have already converted the hexagon-layer (polygons) to lines in a new layer. Commented Jan 7, 2022 at 13:25
• Please Edit the Question instead of adding comments to your own post. The Tour has more basics of GIS SE operation. Welcome to GIS SE. Commented Jan 7, 2022 at 13:42
• Try the Join Attributes by Nearest tool in the Processing Toolbox. opensourceoptions.com/blog/… Commented Jan 7, 2022 at 13:50

On the centroid layer, you can use the following expression with Field calculator to caclulate the distance from the centroids of the hexagon to the closest point of the nearest feature on the layer `park`:

``````length (
make_line (
centroid (\$geometry),
closest_point (
overlay_nearest (
'park',
\$geometry
)[0],
centroid (\$geometry)
)
)
)
``````

Centroids (red points) and line to the nearest park (red line, created with geometry generator and the expression highlighted in yellow). Hexagons are rendered in a graduated style with a white to blue color ramp, based on the expression above that calculates the length of the red lines:

2km hexagon, representing the distance to the parks from Paris, taken form OpenStreetMap data (`leisure=park`). Light areas = short distance to the next park, dark colors = long distance to the nearest park: