TransWikia.com

Flip orientation of Font Markers on line when upside down using QGIS

Geographic Information Systems Asked on November 1, 2021

I would like to have font markers flip when they are upside down but otherwise follow the line angle.
Here is an image of how they look now:

font markers 'AB' on upper line are upside down

I would like them to look like this:

font markers on both lines are not upside down

I achieved this by switching the line direction but I want to do it through the style and I would like to do it at the marker level not the line level.
I have tried a geometry generator to switch the line.

if(y_max( $geometry)>y_min($geometry),$geometry,reverse($geometry))

But this only switches the issue to the bottom line.

font marker on bottom line is upside down

I also tried a data defined override on the font marker rotation with these expressions.

if( @symbol_angle < 180,0,180)
if(y_max( $geometry)<  y_min($geometry),0,180)

One Answer

If you're working with "font markers" for your text, set the following for data defined override of the rotation:

if(line_interpolate_angle($geometry,0)>180,180,0)

This checks, whether the line is "flipped" and if it is, tells the symbology to rotate the text by 180 degrees, otherwise it stays, as it is.

I did some additional testing, and this solution does not take changes of line direction into account.

Answered by Erik on November 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP