8

I have a task I thought some of you might have idea how to solve it.

I have shape and a centroid in it. I need to find longest and the shortest straigt line from the borders of the polygon.

I use QGIS, but have access to ArcMap as well.

4
  • Good question. This tutorial is far to solve your question but could be useful for you! qgistutorials.com/en/docs/nearest_neighbor_analysis.html Jun 1, 2016 at 14:13
  • @WKT The longest distance has to be from the centroid to a polygon vertex so can be done with an exhaustive search over vertices, but the shortest distance can only be done with a search over distances from centroid to polygon line-segments since a segment might pass close to the centroid with its end vertices far away...
    – Spacedman
    Jun 1, 2016 at 14:47
  • This can be done in R, which can read in a shapefile.
    – Spacedman
    Jun 1, 2016 at 17:16
  • 1
    Is there a requirement that the line(s) go through the centroid? Does it need to work for both convex and concave polygons? For polygons with the centroid outside the polygon? Jan 24, 2017 at 18:57

1 Answer 1

1

This is not a very elegant solution, so if you have a lot of polygons, or very large polygons, this process might not be a good solution for you, but –

You could use ‘Densify Geometries’ under Vector>Geometry Tools add an appropriate number of vertices, use the MMQGIS plugin to convert the polygons to points (using the nodes option), and then use the GRASS v.distance algorithm to build a near table. You’ll have to add a distance column to your new 'nodes' layer – make sure it is a decimal number type of an appropriate length and precision. The result should have an attribute table with a column of distances you can sort to get the nearest and furthest distances, and identify the points with the shortest and longest values, from which you can construct the lines you want.

Note that:

  • You’ll have to run each polygon separately.
  • The more vertices you add under Densify Geometries, the more precise your answer and the longer running the process will take.
  • QGIS 2.16.0 does not sort correctly(see this question) and so you may want to update to the newer version.

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.