-
Book Overview & Buying
-
Table Of Contents
QGIS Python Programming Cookbook
By :
Maps in QGIS are controlled through the map canvas. In this recipe, we'll access the canvas and then check one of its properties to ensure that we have control over the object.
The only thing you need to do for this recipe is to open QGIS and select Python Console from the Plugins menu.
We will assign the map canvas to a variable named canvas. Then, we'll check the size property of the canvas to get its size in pixels. To do this, perform the following steps:
Enter the following line in the QGIS Python Console:
canvas = qgis.utils.iface.mapCanvas()
Now, to ensure that we have properly accessed the canvas, check its size in pixels using the following line of code:
canvas.size()
Verify that QGIS returns a QSize object that contains the canvas's pixel size, similar to the following format:
PyQt4.QtCore.QSize(698, 138)
Everything in QGIS centers on the canvas. The canvas is part of the QGIS interface or iface API. Anything you see...
Change the font size
Change margin width
Change background colour