5

I'm using QGIS 2.18.4, I wanted to add "scale text" but can't find the tool for adding the scale text on the composer. I only see an option of add text and not "scale text" as in other GIS Software like ArcGIS. Is there anyone who knows this?

1
  • You dont know what you want. Who need scaled text? Try with font size.
    – nagib
    Mar 19, 2017 at 13:16

4 Answers 4

15

If you want to add a numeric scale like 1:10000 you can add a normal scalebar first and then change the style to 'Numeric' under Item Properties > Main Properties of the scalebar element.

0
3

You can register expression function to get your map scale. For example:

from qgis.utils import iface 

@qgsfunction(args='auto', group='Custom')
def get_composer_map_scale(comp_window_title, feature, parent):
    composer_views = iface.activeComposers()
    my_composition = None
    for view in composer_views:
        if view.window().windowTitle() == comp_window_title:
            my_composition = view.composition()
            break
    if my_composition is not None:
        # adjust map id below if you have more maps in the composer
        comp_map = my_composition.getComposerMapById(0)
        scale = '{:.0f}'.format(round(comp_map.scale(), 0))
        return scale
    else:
        return 'Unknown'

And use it in your HTML box or label:

Scale 1:[%get_composer_map_scale( 'Composer 1' )%]

where 'Composer 1' is your composer title.

3

In QGis 3.x you can add variables in text item with something like [%'1 : ' || round(map_get(item_variables('Main'), 'map_scale'),0)%]

3
  • Thanks for posting an updated information. Unfortunatly its not working. Does someone know which function queries the live map scale?
    – Velester
    Oct 20, 2020 at 12:44
  • I have tested, it works. You have to remplace "Main" with the name of your map (you find this information in the field "Item ID - id". You can also add a scalebar and choose the style "numeric" Oct 21, 2020 at 7:17
  • Thanks a lot. You kinda opened a whole new world to me there. Will give the variables closer attention now :)
    – Velester
    Oct 23, 2020 at 9:18

Your Answer

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

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