# Calculate Distance (in miles) from Point to Polygon Edge in QGIS

I am attempting to calculate the distance from a point to the nearest polygon edge (county boundary). I have approximately 80 points and want to find the closest county edge for all of the points and calculate the distance in miles. I am using QGIS because I only have a basic license in ArcGIS Pro. I have tried all of the distance tools with no luck. I read about the NNJoin plug-in, but I can't seem to get that to work either.

You can:

1. Convert your polygons to lines with "Polygons to Lines"

2. Calculate the distance to nearest line with Field Calculator. Change Lines to the name of your line layer:

`distance(\$geometry, array_first(overlay_nearest(layer:='Lines', expression:=\$geometry)))*0.000621371192`

which measures the distance from each points geometry to the nearest lines geometry.

My coordinate system is in meters so I multiply the result with 0.0006... to get miles

(Field type should be Decimal number (Real), not integer)

• Is there a way to do this and tell it a specific points layer? I have multiple in my project. Commented Jun 16, 2023 at 10:45
• That's what I'm doing. I've opened the attribute table of the "Random points" layer and Field calculating it
– Bera
Commented Jun 16, 2023 at 16:19

To create a line from the point to the closest point on the boundary of the nearest polygon and then measure the length of that line, use this expression:

``````length(
make_line (
\$geometry,
closest_point (
boundary(
overlay_nearest (
'polygon',  -- change to the name of your polygon layer
\$geometry
)[0]
),
\$geometry
)
)
)
``````

A modofied version of the expression (to convert m to km and round the result) labels to point layer with the distance to the nearest point on the polygon's boundary - thus the length of the black lines that are added for visualiziation purpose only:

• Is there a way to specify the points layer? My project has multiple. Commented Jun 16, 2023 at 10:48
• You apply the expression on the point layer, so you choose which one it is. Commented Jun 16, 2023 at 12:29