2

How can I display labels for line features in a QGIS line layer, where the label should appear outside a polygon if the line feature is inside the polygon, and otherwise appear as it is? I have activated the "name" field for labeling the line features.https://i.sstatic.net/I3C3p.png

I tried the below expression but it is not working.

difference ( $geometry, buffer ( aggregate( 'Rohrlage', 'collect', buffer ($geometry,15) ), 0 )) 

enter image description here

1

1 Answer 1

5

Using this expression, if the line is fully within a polygon geometry, the @within variable will return the the containing polygon and use its boundary as the placement. Otherwise, the original line geometry is used.

Change 'poly' for your polygon layer name.

with_variable('within', overlay_within('poly', @geometry)[0], case when @within is not NULL then @within else @geometry end ) 

enter image description here

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.