5

I want to create a symbology (line type) for a point layer in QGIS. This line must be perpendicular to the segments of a polygon. I attach an image: enter image description here

To do this I entered an expression in the rotation section of the symbol enter image description here The expression is this:

degrees(
    azimuth(
        $geometry,
        closest_point(
            aggregate(
                'lotto',
                'collect',
                $geometry,
                intersects($geometry, $geometry)
            ),
            $geometry
        )
    )
)

However the symbology of points 1, 2, 6, 7 is correct, while that of points 3, 4, 5 is not, as the calculated rotation value is 0.

How can I also make points 3, 4, 5 perpendicular to the various segments? is it possible by modifying this expression or do I have to use another approach.

The layers in question are two different, a point layer and a polygonal one.

Babel
  • 71,072
  • 14
  • 78
  • 208
Ma6matto
  • 53
  • 3
  • 1
    Maybe you can use something similar to: https://gis.stackexchange.com/questions/428385/rotating-point-layer-according-to-line-layer-in-qgis/428391#428391 – BERA May 25 '23 at 11:11

2 Answers2

3

Your approach works for points outside the polygon. However, points inside the polygon are already the closest point to themselves, so the azimuth returns 0.

Try converting the polygon to a line.

Wrapping the inner $geometry in an exterior_ring seems to work (on a small sample size!):

degrees(
    azimuth(
        $geometry,
        closest_point(
            aggregate(
                'lotto',
                'collect',
                exterior_ring($geometry)
            ),
            $geometry
        )
    )
)

enter image description here

Tom Brennan
  • 4,787
  • 6
  • 26
2

I suggest you convert your polygons to lines, split the lines at each vertex, calculate the azimuth of each line using the field calculator, add 90 to the azimuth and then join the modified azimuth attribute to your points. Then you can control the rotation of the points via data defined override using the joined attribute.

Erik
  • 16,269
  • 1
  • 24
  • 43