Using the atlas functionality in QGIS 2.14 The canvas scale varies according to the object in question (national parks).

I want to have a numbered scale based on the canvas print size. I tried using scale in a text box:

[% $scale %]

This gives me "0" and is not useful. Either this is an error, or I am not using it right.

Requesting pagewidth and dpi works fine. Is there a different way to do this? Based on pagewidth and real world maxx and minx I should be able to calculate the scale. But I can not find any variables for maxx and minx.

How can I present scale on the atlas generated maps?

2 Answers 2


Insert a scale bar in the normal way, then change the Style drop down to Numeric and you will get a scale as 1:XXXXX

enter image description here

  • Good and precise answer to my question. Still wondering why the scale variable does not give a proper value.
    – ragnvald
    Apr 19, 2016 at 7:21
  • 1
    The help on $scale mentions that it is only available in some contexts. My understanding is that you use this in conjunction with other functions, rather than as a return for a value Jun 1, 2016 at 15:20
  • To insert current map's scale value in label as text see this answer: gis.stackexchange.com/a/332759/35561 Aug 22, 2019 at 11:59

If you just need a standalone number, a numeric scalebar is fine but if you want to insert the scale value into a label, a function is required.

(From the QGIS documentation)

Choose "Insert an expression...", "Function Editor" and paste the following (Also give the function list a name and click "Load")

from qgis.utils import iface
from qgis.core import *
from qgis.gui import *

@qgsfunction(args="auto", group='Composer')
def composeritemattr(composername, mapname, attrname, feature, parent):
    composers = iface.activeComposers()
    # Find the composer with the given name
    comp = [composer.composition() for composer in composers 
                if composer.composerWindow().windowTitle() == composername][0]
    # Find the item
    item = comp.getComposerItemById(mapname)
    # Get the attr by name and call 
    return getattr(item, attrname)()

Then you can use this expression in your print composer labels -:

composeritemattr('Composer 1', 'Map 0', 'scale')

(Replace the values with the actual name of your composer and map window)

I have found that sometimes this returns a value like 1000.000000000001 so I wrap it in a round() function.

Your Answer

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

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