3

I want to calculate the maximum distance between a point and the boundary of a polygon (representing an animal's home range).

Here is an example of the point layer, always within the polygon layer: enter image description here

When I needed the minimum distance, I used "QGIS GRASS > v.distance > minimum distance to nearest feature".

Does anyone know how to calculte the maximum distance in QGIS/GRASS?

  • You can use PyQGIS instead of QGIS/GRASS. – xunilk Oct 5 '16 at 6:16
2

You probably need the maximum minimum distance between all your values. For this reason you don't have available this option in v.distance. However, it's not very difficult to determinate it in QGIS by using PyQGIS. Next code does the work (in your case change the names of respective shapefiles):

registry = QgsMapLayerRegistry.instance()

points = registry.mapLayersByName('Random points')
polygon = registry.mapLayersByName('polygon2')

feats_point = [ feat for feat in points[0].getFeatures() ]
feat_polygon = polygon[0].getFeatures().next()

geom_polygon = feat_polygon.geometry().asPolygon()

geom_polygon_line = QgsGeometry.fromPolyline(geom_polygon[0])

distances = [ feat.geometry().distance(geom_polygon_line)
              for feat in feats_point ]

print min(distances), distances.index(min(distances))
print max(distances), distances.index(max(distances))

I ran above code with the shapefiles of next image. At the Python Console of QGIS were printed "minimum" and "maximum" distances for comparison purposes. Indices of respective points were also printed for corroborating the correct code execution. For this reason it could be selected these features (yellow color) at next image.

enter image description here

  • The code worked perfectly, but I would only get one value. Now I want to get the maximum value for each point; how can I obtain that? – mtao May 15 '18 at 20:07
  • I suppose that 'each point' is referred as 'each polygon vertex'. In this case, you need to determine for each polygon point what is its farthest vertex and afterward, for the latter, which is closest point inside polygon. Maximum distance is determined with these pair of points. However, this is another question. – xunilk May 21 '18 at 4:11
2

This isn't strictly QGIS, but if you can be bothered to convert any of your datasets into PostGIS (which is easy with the DBManager plugin), then http://postgis.net/docs/ST_MaxDistance.html will be your friend.

  • Ok, thanks! I have never used that but I'll give it a try! – mtao Oct 4 '16 at 18:00

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.