5

Is there a possibility to determine the longest side of a polygon with QGIS?

As I need to do that for hundreds of polygons I would prefer an automized method (like a plugin).

So far my idea was:

  • transforming a polygon into a line
  • cut it on the vertices
  • measure the length
  • here I became stuck, how to become the longest line without checking the whole bunch of lines one by one?
2

3 Answers 3

5

If you can use PostGIS, try using the ST_LongestLine() function like this:

SELECT ST_LongestLine(geom, geom)
FROM mypolytable;

This will find the longest line that can be drawn within each polygon geometry. Note that I'm using this function that references the same geometry column geom twice.

3
  • Thanks for your answer. The function you mentioned returns the 2-dimensional longest line points of two geometries but Im looking for the longest line of a single polygon. Am i wrong? Anybody else an idea??
    – ragavendra
    Commented Apr 24, 2013 at 15:53
  • 1
    Two geometries is actually one geometry when you reference the same geometry twice, as I have described. Did you try it?
    – Mike T
    Commented Apr 24, 2013 at 23:40
  • 1
    @MikeT It is cool function I did not know exists, but I guess OP needs longest segment of polygon boundary which is something very different from what this function returns.
    – Miro
    Commented Oct 8, 2020 at 12:02
4

Let's assume there is a polygon layer called 'poly' with its attribute table, see image below.

input

Step 1. Proceed with the "Polygons to lines"

step_1

Step 2. Apply the "Explode lines"

step_2

Step 3. Use the "Extract by expression" with the following expression (includes the maximum() function)

$length = maximum($length, "id")

step_3

2

Let's assume there is a polygon layer called 'polygons' with its attribute table, see image below.

input

Step 1. Proceed with the "Polygons to lines"

step_1

Step 2. Apply the "Extract vertices" two times, it will be important for the next step

step_2

Step 3. Make use of "Join by lines (hub lines)" between the two layers with vertices. Afterwards the application of the "Fix geometries", "Remove null geometries" and "Delete duplicate geometries" is probable

step_3

Step 4. Employ the "Extract by location" (are within for geometrical predicate) between the Results of the Step 3 and Step 1

step_4

Step 5. Use the "Extract by expression" with the following expression (includes the maximum function)

$length = maximum($length, "id")

step_5

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.