Book Image

Mastering QGIS

Book Image

Mastering QGIS

Overview of this book

Table of Contents (18 chapters)
Mastering QGIS
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Exploring a QGIS API in the Python Console


The QGIS APIs can be browsed in the documentation web page, but if you want to access the documentation directly in the Python Console, you can use some useful Python commands. The help command shows a synthesis of the API information available in the web documentation. Try to edit Python Console with the command:

help(iface)

The console will show all the methods of the QgisInterface class and a synthetic example of how to use this in Python syntax instead of C++ syntax. For example, if you want to show the result type of the call iface.activeLayer type:

help(iface.activeLayer)

The following lines will be displayed:

Help on built-in function activeLayer:
activeLayer(...)
QgisInterface.activeLayer() -> QgsMapLayer

This shows that the activeLayer call returns data that is a QgsMapLayer data type.

The Python dir() function gives you more detailed information, showing a list of all the methods belonging to a class.

Tip

Try typing dir(iface) and compare it...