15

I have two vector layers: one point and one polygon and I want to calculate the minimum distance of each point from the polygons (ie the distance from the closest point of the closest polygon).

Is there any available plugin in QGIS for doing this?

4
  • 1
    you mean polygon vertices, the centroid or something else? Jun 22, 2012 at 20:35
  • This task would be better handled by postgis.
    – Pablo
    Jun 23, 2012 at 0:03
  • I mean the distance from the borders of the polygon (actually it's the distance of observed seabirds in the sea from the coastline that I want to calulate)
    – Sylvia
    Jun 23, 2012 at 10:49
  • Pablo, unfortunately I don't know how to use PostGIS and I can't write code...
    – Sylvia
    Jun 23, 2012 at 11:05

4 Answers 4

13

Converting your polygon to points first is a bad idea. You will not be calculating the distance to your polygon, you will be calculating the distance to the closest node of your polygons (not the edges which may be closer). You can use the NNJoin Plugin to get accurate measurements to your polygon. Make sure your layers are in the same projection before doing analysis.

2
  • 1
    The QGIS NNJoin Plugin will take care of coordinate system transformation. But you should make sure that you use a projected coordinate system for the join dataset (the input dataset will be transformed to the coordinate system of the join dataset if their coordinate systems differ). Apr 18, 2015 at 23:41
  • NNjoin worked well for me.
    – grego
    Jan 21, 2022 at 23:32
6

If you want to use QGIS, the GRASS v.distance function in the GRASS plugin should do the job. The NNJoin plugin should work for small datasets, and is less cumbersome to use.

The NNJoin plugin uses the QgsGeometry.distance() function (which uses the GEOSdistance) to calculate the distances.

3

First convert the polygon to points:

Vector -> Geometry Tools -> Extract Nodes

Add this new layer, then calculate a distance matrix between your points layer 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

1
  • This is a good answer to the original question, but the question has since been modified in a comment. Extract nodes and Distance Matrix may not find the closest place on the boundary (the closest place may be between the points of the boundary polyline). GRASS v.distance or the NNJoin plugin will. Mar 18, 2018 at 23:28
2

Try Hub Distance in the MMQGIS plugin.

http://michaelminn.com/linux/mmqgis/


References:

1
  • 2
    Hub distance did the job, but for the record, I first converted the polygon into a point layer and calculated the minimum point-to-point distances. With the polygons it was calculating the minimum distance from the centroids or the middle of the coastal boundary
    – Sylvia
    Jun 23, 2012 at 13:58

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.