2

I have a problem. I'm offsetting lines with the attribute field "offset". In the image the blue line is the original geometry. I was able to retrieve the offset value the attribute. (The callout line is now on the red line). But lines have a direction and so the offsetvalue depends on their direction. If i add a minus before offset it moves to the brown line where it should be automatically.

How do I have to change the code to get the geometry direction automatically instead of using the minus symbol which just works for one direction?

enter image description here

make_line(
    start_point($geometry),      
        project(                 
        end_point($geometry),
            -"Offset",            
        radians(90)              
    )
)

enter image description here

The original thread was: Making callout lines follow feature offset

1 Answer 1

1

A problem you face is that the offset of the callout end point is taking place only in the x direction, so the end of the callout is not perfectly aligned with the offset line.

Try this expression:

-- make variables of the start and end points of the original callout  
with_variable('start', start_point($geometry),
    with_variable('end', end_point($geometry),
        make_line(
            @start,
            project(
                @end,
                "Offset",
                azimuth(@start, @end)   -- get the callout line direction for the point projection
            )               
        )
    )
)

You may have to add the minus sign before "Offset", depending on your line directions.

Important

Be sure to enable the Line orientation dependent position option in the label placement tab:

enter image description here

Result

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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