3

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?

3
  • EDIT: I have already converted the hexagon-layer (polygons) to lines in a new layer.
    – green
    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.
    – Vince
    Commented Jan 7, 2022 at 13:42
  • Try the Join Attributes by Nearest tool in the Processing Toolbox. opensourceoptions.com/blog/…
    – Ben W
    Commented Jan 7, 2022 at 13:50

1 Answer 1

6

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: enter image description here

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: enter image description here

Your Answer

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

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