It is relatively easy to calculate distances from points to a polygon in ArcMap by doing a join and selecting the option for creating a field containing the minimum distance information. i.e. it generates a field containing the distance from each point to the boundary of the polygon.

Is there a relatively simple way to do the same thing in QGIS? I've tried NN Join, but it crashes each time I try to use it. I've also tried the Processing toolbox's 'distance to hub', but it gives the distance to the centroid of the polygon instead of the boundary.


There's probably several methods to achieve this but I will just mention a couple. The first requires several steps. I've created a couple of simple layers with a point layer (1 feature) and a polygon layer (3 features):

Point and polygon layers

Use the Polygons to lines tool, I just seach the Processing Toolbox and use all tools from there:

Polygon to lines

Then use Convert lines to points from SAGA. Select Yes for the Insert Additional Points option and use a very low value for the Insert Distance (I used 0.01, note that this is measured in metres). This adds a point every 0.01m so the lower this value is, the more accurate you will be when finding the nearest distance:

Line to points

Now we can use the Distance to nearest hub tool. Using the layer that's converted from lines to points as a source allows the distance to be calculated from each of those points to the original point layer. Feel free to change the other options to suit your needs:

Distance to nearest hub

Now we can see the distance lines, I'm also showing the polygons to lines layer purely for visualisation:

Distance calculated

Now that we have the output layer with all the distances, we need to find the minimum distance from each 'polygon' by opening its Attribute Table. The Name column is associated with the original polygon layer. Each of the 3 features has a name corresponding to their direction in respect to the original point layer (you will have other attributes ofcourse so use an attribute that is unique to that polygon. You can always create new attributes if you need to). Click the HubDist column so that the arrow is pointing upwards (this sorts the column from smallest values to largest). Next select the Advanced Filter (Expression) from the menu at the bottom of the table and use a command to filter out each polygon's unique attribute such as:

"Your_Column" Like 'Your_Polygon_Attribute'

Attribute table

Select the topmost feature. Next replace Your_Polygon_Attribute (in my case it's Right) with another polygon attribute and apply. Hold ctrl and select the topmost feature. Repeat for more polygons (there's probably a nicer command to use which can filter all this out!). Once you're done, you can select the Show Selected Features which will now show you which line is the nearest from your point to the boundary of the polygon. You could if you wanted, Show All Features, click the Invert Selection button and delete all the other lines leaving you with the nearest lines to the boundary.

Selected features

So now, you should have the nearest distance from your point to the boundary of each polygon.


The other method, which I have read should also work, would be to use v.distance from GRASS to calculate the distance between 2 features. The following are features which can be defined for the 2 input layers.

FROM input layer:

  • Points
  • Centroids

TO input layer:

  • Points
  • Line
  • Boundary
  • Centroid
  • Area

Hope this helps!

  • Most welcome buddy, hope you get the results you need!
    – Joseph
    Jan 19 '15 at 10:41

If you are willing to use a QGIS plugin, you could consider the simple to use NNJoin plugin. The GRASS plugin provides the powerful tool v.distance. Both will add a distance attribute that contains the distance to the nearest feature in the join layer, together with the attributes of this feature. NNJoin accepts point, line and polygon layers for both the input and the join layer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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