Exploring iface and QGis
The iface
class used in the preceding snippets is important in every PyQGIS code; it is used to access most graphical QGIS components, from displayed layers to the toolbar buttons.
Note
The iface
class is a Python wrapper for the C++ class, QgisInterface
, which is documented at http://qgis.org/api/classQgisInterface.html. Most QGIS classes have a Qgs
prefix. Some special classes can have the Qgis
or QGis
prefixes.
The prefix Qgs
is the Qt
namespace registered by Gary Sherman, the QGIS creator, so Qt (Q) and Gary Sherman (gs).
The most common use of the iface
class is to get a reference of the canvas
where maps are displayed:
canvas = iface.mapCanvas()
The class can also be used as a shortcut to load raster or vector layers; ...
Get Mastering QGIS - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.