2

I'm trying to label features using the geometry generator (QGIS 3.8). I used the following expression to build a simple circle :

buffer(centroid($geometry), 500)

In Placement i used Using Perimeter (curved)

The labeling is working pretty good except some of my features label are written clockwise and some counterclockwise. How could i control this rendering ?

Furthermore i would like the mid-point of my labeling string to be at the most northern point of the circle ...

How could i achieve that ?

Snaileater
  • 5,743
  • 1
  • 15
  • 26

1 Answers1

2

For clockwise/counterclockwise fix, you can allow upside-down labels. In label rendering tab set Show upside-down labels to allways.

enter image description here

For centering the label to the north, I figure out a workaround based on Using QGIS Geometry Generator to get rectangle from point?. Using geometry generator in label placement tab, you can create buffer of tiny polygon witch starts at such a place that the label is then rendered on top. Just adjust the buffer size to your needs.

buffer(geom_from_wkt( 
    'POLYGON(('|| 
        (x(centroid($geometry)))||' '||(y(centroid($geometry)) - 0.0001) ||','||
        (x(centroid($geometry)))||' '||(y(centroid($geometry)) + 0.0001) ||','||
        (x(centroid($geometry)) + 0.0001)||' '||(y(centroid($geometry)) - 0.0001) ||','||
    '))'
    ),
    0.3
)

enter image description here

Note that geometry generator for label placement is available from version QGIS 3.8

Oto Kaláb
  • 6,895
  • 3
  • 29
  • 50
  • So where do you put that buffer expression? Do you add a geometry generator symbol layer? – csk Oct 14 '19 at 15:54
  • @csk No, in version 3.8 is geometry generator also for label placement (in Labels -> Placement tab) – Oto Kaláb Oct 14 '19 at 18:06
  • It might be worth mentioning that in your answer, otherwise people using the current LTR will have trouble understanding your answer. – csk Oct 15 '19 at 15:47
  • Yes, but I followed the OP, where is mention use of geometry generator for label placement in version QGIS 3.8. For completeness, I added note to my answer. – Oto Kaláb Oct 15 '19 at 17:33
  • @Oto i'm using indeed qgis 3.8 but i'm struggling using your expression ... where should i put it ? is it supposed to replace my former buffer(centroid($geometry),500)? how would my text be bended in that case ? What kind of units should be used in such expression ? – Snaileater Oct 15 '19 at 18:52
  • @snaileater Yes exactly, it is a replacement, you have tu put the expression to geometry generator in label placement tab. buffer function and units stay same so you can use 500. But instead of yours centroid($geometry) it use geom_from_wkt() to create tiny triangle around centroid angled that way that the label is then rendered on top. – Oto Kaláb Oct 15 '19 at 19:04
  • ok it's working, thanks ! ... but i'll need some time to understand why it is working ... lol – Snaileater Oct 15 '19 at 19:53
  • :) You can use the geom_from_wkt() part in symbology geometry generator, which gnerate the polygon as symbol, so you can see what is happening in the background when you use the expression for labels. – Oto Kaláb Oct 17 '19 at 09:01