I have a layer of rubber bands. They are placed on roads before crosswalks to make cars slow down.

enter image description here

In QGIS + PostGIS I have them represented with polygons (orange rectangles). All the polygons have rectangular shape (2 long sides and two narrow sides). Is there any way to make the inner black lines parallel to the narrow sides?

enter image description here

enter image description here

My approach would be to develop a function that takes the narrowest side (Polyline) of the polygon and calculates the degrees of inclination with respect to the x-axis. And apply this rotation automatically to the lines of each polygon. I am not sure how to develop the function either.

Is there any simpler solution?

  • 1
    Wild... I though main_angle($geometry)+90 would return exactly what you needed for data defined override of the line filling orientation... but it doesn't. Maybe my temporary features are too crudely drawn.
    – Erik
    Jan 30 at 11:03
  • It gets really close but lines are not perfectly parallel. In some polygons they are perfect with +92, in other polygons with +95, etc..
    – Egidi
    Jan 30 at 11:15
  • The QGIS style hub has an Polygon Oriented Hatch style : plugins.qgis.org/styles/59 (it seem to style with 45° angle not 90° as you want), you may try to get it and adapt to your case (for reference the expression for rotation is : "180-degrees( azimuth( point_n( oriented_bbox( $geometry), 1), point_n( oriented_bbox( $geometry), num_points(oriented_bbox( $geometry))-2 )))")
    – J.R
    Jan 30 at 11:25
  • I found that you have to put a negative sign infront of the expression for some reason. -main_angle($geometry)+90
    – Baswein
    Mar 2 at 19:05


Browse other questions tagged or ask your own question.