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):
Use the Polygons to lines tool, I just seach the Processing Toolbox and use all tools from there:
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:
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:
Now we can see the distance lines, I'm also showing the polygons to lines layer purely for visualisation:
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'
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.
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:
TO input layer:
- Points
- Line
- Boundary
- Centroid
- Area
Hope this helps!