4

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

7

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

array_max(array_foreach(
    geometries_to_array(segments_to_lines($geometry)),
    length(@element)
)) / 3

1

2
  • 1
    What version of QGIS is this solution for?
    – Cushen
    Commented May 30, 2023 at 2:27
  • @Cushen, 3.30 ‘s-Hertogenbosch.
    – Mayo
    Commented May 30, 2023 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.