3

I have made an example project to help me illustrate what my problem is. I have about 900 curved lines which i want to label using the geometry generator. My label should consist of a line extending from the middle geometry of the line exactly perpendicular. I am labeling an urban map so it would be good if the position on the line can be edited via the attribute table, since there's a danger my labels might overlap or not be in the correct position.

make_point(
    x(line_interpolate_point($geometry, length($geometry)/2)),
    y(line_interpolate_point($geometry, length($geometry)/2))
)

And screenshot :

enter image description here

and it should look something like this :

enter image description here

EDIT : I used this rather complex code in expression editor to find the angle of each line :

(atan((xat(-1)-xat(0))/(yat(-1)-yat(0)))) * 180/3.14159 + (180 *(((yat(-1)-yat(0)) < 0) + (((xat(-1)-xat(0)) < 0 AND (yat(-1) - yat(0)) >0)*2)))

EDIT2 Far easier :

 round(degrees(bearing(start_point($geometry), end_point($geometry),
'EPSG:3857',
'EPSG:7030')),0) 

I know have an attribte of each angle.

I am able to draw a line where they all go in the same direction using the following code :

make_line(
   
    make_point(
        x(line_interpolate_point($geometry, length($geometry)/2)),
        y(line_interpolate_point($geometry, length($geometry)/2))
    ),
    make_point(
        x(line_interpolate_point($geometry, length($geometry)/2)) + 20,
        y(line_interpolate_point($geometry, length($geometry)/2)) + 20
    )
)

enter image description here

how can i add my angle attribute to get my desired result?

1 Answer 1

2
make_line(
    array(
        make_point(
            x(line_interpolate_point($geometry, length($geometry)/2)),
            y(line_interpolate_point($geometry, length($geometry)/2))
        ),
        make_point(
            x(project(line_interpolate_point($geometry, length($geometry)/2), 100, radians("winkel"+90))),
            y(project(line_interpolate_point($geometry, length($geometry)/2), 100, radians("winkel"+90)))
        )
    )
)

Is the answer.

Not the answer you're looking for? Browse other questions tagged or ask your own question.