QGIS Python Extensions

The idea for this session was to try to write a QGIS plugin in Python.

Since no one present had actually attempted this before, we ended up talking a bit about working with Python and then looked at the sample framework.

Here's a link to the page we used in the session: http://qgis.org/pyqgis-cookbook/plugins.html

Things to know
QGIS is a GIS desktop application written on the QT GUI framework, so Python plugins are built using PyQT. After you have decided what your plugin is going to do, lay out its user interface in "QT 4 Designer". Using the sample framework as a template, connect the controls in your UI to your python code.

The QT SDK for programmers is available for free. If you are an Ubuntu user, install the packages 'qt4-designer' and 'python-qt4' Using QT Designer is equivalent to designing a GUI for Visual Basic or in Visual Studio; you have a toolbox of widgets (buttons, sliders, textboxes, etc) that you can drag and drop onto container(s).

The sample we looked at was a trivial "Hello World" thing. (Clicking the "run" button puts text into the QGIS console.) There are other samples available, but we only had an hour. We vowed to do a more complete session at an upcoming PDX GEO meeting. Obviously doing non-trivial things is where it gets interesting...

Working with Python
You really will want an advanced editor / IDE for python. It makes things a lot easier.

One mentioned in the section was pyscripter - intellisense for coding (windows only?)

Another one that's really nice is Komodo from ActiveState. It runs on all platforms. There are both commercial and free versions. Komodo also supports other languages like PHP and Perl. The commercial version supports debugging, including debugging on remote platforms.

If you are already a Java programmer you probably use Eclipse and there is a Python plugin for it. Eclipse is free.

Return to 2011 Unconference Sessions.