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?
4 Answers
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.
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.
In QGis 3.x you can add variables in text item with something like [%'1 : ' || round(map_get(item_variables('Main'), 'map_scale'),0)%]
-
Thanks for posting an updated information. Unfortunatly its not working. Does someone know which function queries the live map scale?– VelesterOct 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 :)– VelesterOct 23, 2020 at 9:18
Same as these?:
- Integrating numeric scales into a text or HTML box in QGIS print composer
- Is it possible in QGIS print composer to include a numeric scale in an html box?
According to OSGEO - QGIS developer it is not possible, but it will be in version 3.0. GitHub commit.