I want to be able to calculate the longest edge of a rectangle polygon to create an expression for a style.

The styled rectangles will have variable orientations, widths and lengths.

I want to use this longest length to create an expression for the spacing of the Line Pattern Fill of the polygon style. The spacing will be set to 1/3 of the longest length of the polygon, so that the rectangle is visually divided into three segments (the rotation is already set to be -(main_angle($geometry))).

As an example, the distance of the longest edge is 3.501 m, which divided by three equals 1.167 m. This value (1.167 m) is set as my spacing. The effect is what I am after, I just want to automate this without manually calculating the 1/3 of the longest edge!

enter image description here

1 Answer 1


Use this expression, and remember to set the units to Map Units and Clipping to Clip Lines Before Render.

)) / 3


  • 1
    What version of QGIS is this solution for?
    – Cushen
    May 30 at 2:27
  • @Cushen, 3.30 ‘s-Hertogenbosch.
    – Mayo
    May 30 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.