2

In Relating text buffer to text size in QGIS? I displayed various polygon sizes : the objective of my research was to try to adjust automatically the buffer size of the text to the font size because the buffer tended to be too large for little texts.

I'm now looking for a way to adapt the font size to the polygon area. This way, i won't have to put it into the attribute table and fix manually the font size i need.

2
  • @Midavalo Thanks for the edit, i didn't knew that when you paste the url, it's replaced but the full link with the question title :) Made me realize I had copied the wrong link :)
    – gisnside
    Apr 24 '17 at 20:30
  • If it's a Q&A from the same SE site, the title will auto-populate. It will also automatically update if the title is modified.
    – Midavalo
    Apr 24 '17 at 20:35
4

EDIT June 2018: easier solution in QGIS 2.18+ !

It's possible to do it directly, without a virtual field as in my previous answer :

  • Open the Label properties
  • At the end of the line, click on the data defined icon
  • Select Edit
  • Write in the field ln($area) (or log(base, $area) as suggested by @Stephen Kay in comments, with base an integer you choose)
  • If necessary, do the same for the text buffer and write ln($area)/15 in the data defined properties of the size.

EDIT June 2018: I leave my previous solution below for info

An easy way to do this is by using the ln() function (for example).

  • create a virtual field named VRT_FONT
  • Use the formula ln($area)
  • Set the lable font size to the data defined field VRT_FONT
  • Draw new polygons, it will label automatically your polygon depending on it's area.

This basic formula answers my needs but you can of course tweak it to suits yours by adding/multiplying values (or else).

Tip : you can combine this with the following tip : do a virtual field VRT_BUFF with the formula "VRT_FONT"/15 and set the lable font buffer to this field to have an area adaptive buffer too. Tip 2 : you can modify the formula to fit your own scale needs and the size of buffer you would like.

What it does :

With_tip

The field properties :

With_tip_properties

The attribute table :

attributes

A new polygon :

With_tip 2

2
  • 1
    nice one! you could also use log(base, $area) and experiment with the base value (somewhere between 1 and 10 should work well)
    – Steven Kay
    Apr 24 '17 at 20:17
  • Thanks for the advice, i'll have a try at it too :). My formula was an empirical one, but I guess there must be smarter ways to do it :)
    – gisnside
    Apr 24 '17 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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