# Estimating a location at the minimum distance between a point and a polygon

I have two types of objects (i) polygons representing postcode areas, and (ii) points representing telephone exchanges.

I want to find the part of the polygon that is closest to the exchange and place a point there (see the red X in the image below). The green lines in the below image are fanning out from the exchange location.

So far I have followed this example and converted the polygons to lines, and then tried to join the attributes of the point and line layers by closest distance]3. However, using the MMQGIS Distance to Nearest Hub tool it calculated the distance to the polygon centroid.

And using NNJoin, it correctly calculated the distance between the red X and the exchange, but it did not insert a point in that location. Please see the below image for more context

How do I put a point or some kind of feature at the red X as an estimate of broadband cabinet location?

• You're looking for the equivalent of postgis St_closestpojnt postgis.net/docs/ST_ClosestPoint.html the link gives a visual example Commented Jan 4, 2017 at 14:18
• Have you tried the GRASS tool v.distance? Commented Jan 4, 2017 at 15:51

First convert the polygon to points:

`Vector > Geometry Tools > Extract Nodes`

Add this as a new layer, then calculate a distance matrix between your exchange point and the new polygon-points layer you just created:

`Vector -> Analysis Tools -> Distance Matrix`

Be sure to choose `Use only the nearest (k) target points as 1`

The output will be a csv file - take the points from your shortest distance and then use `MMGIS > Create > Hub lines` to join the two points

• This won't necessarily give you the closest point. Imagine a rectangle centred a little above the point - the closest point in this case isn't a node from the rectangle. Commented Jan 4, 2017 at 11:40
• True but we're not dealing with a rectangle here Commented Jan 4, 2017 at 13:49
• ndawson's comment is valid, and the rectangle is just an example that illustrates his point. His comment applies to any line segment that is a part of the polygon boundary, as long as the (exchange) point is closer to the line segment than to any of the line segment's two end points (and the line segment is a part of the polygon's convex hull). Commented Jun 26, 2017 at 21:55