I'm trying to fill entities (polygons from 3 to x points) with a texture that I want to align with the 'general' orientation of each polygon, ie, I need a formula to assign to the Rotate field of the polygon style (red circle on the image).

I guess the function would have to determine global polygon orientation by reducing the polygon to its box and calculate the ration height/length.

Unfortunately, I'm not skilled enough with programming. How would you do that?

Exemple of what I try to achieve QGIS style window

  • Could you elaborate a bit on what you mean by orientation? It seems like it could be a bit subjective which way an irregular polygon is "facing". Maybe show an example of some polygons and which way they face according to your definition?
    – hexamon
    Commented Mar 4, 2020 at 9:39
  • I added an exemple. Texture lines are supposed to be facing polygon orientation. Please ask if more needed.
    – Laurent
    Commented Mar 4, 2020 at 10:07

1 Answer 1


To have a polygon layer with a texture orientated according to the rotation of the polygon you can use this expression:

angle_at_vertex(shortest_line(centroid(oriented_bbox($geometry)), boundary(oriented_bbox($geometry))),0)

Add the expression in the Orientation variables of the fill as shown in the image

enter image description here

With this expression, the orientation of the pattern will be calculated according to the angle created by the intersection of the shortest line between the polygon centroid and his oriented bounding box and his bounding box perimeter.


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.