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.

1

2 Answers 2

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

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.