Friday, July 6, 2018

Python QGIS Tutorial: Getting Started

Welcome to the first tutorial about QGIS Python Programming. This tutorial will discuss about the python console in QGIS. You can skip this tutorial if you already familiar to work with python console in QGIS.

Getting Started with QGIS Python Programming

To get started using python code in QGIS, we are using Python Console. Click the python console in the plugins menu as in figure 1.
Open Python Console
Figure 1. Open Python Console

The python console will be docked at the bottom of QGIS window as in figure 2.

Qgis Window with python console
Figure 2. Qgis Window with python console

In the console you can type the python syntax. for example to check the python version we can use the following code.

import sys
print (sys.version)

Type those code in the console and hit enter you will get the python version and some info of the machine like figure 3.

Python console
Figure 3. Python console
In the console we can just type a line of syntax or code and then execute it. Although we can make a function or a loop process in it, but it would be difficult to handle. That's why we use the console just for short purpose, such as to get a variable, object, list, etc. For a complex or long coding we are using the editor. To access the editor just click the paper icon with a pencil as in figure 4.

Python editor
Figure 4. Python editor
In the figure 4 can be seen a blank editor. In this editor we can write our coding and can be saved for the next purpose.

That's all the tutorial how to get started QGIS with python programming. In the other QGIS Python Programming post we will make a journey to explore more about this topic. Hopefully you can have fun with it.


Post a Comment