The new era: QGIS and Python

Few days ago I've seen in PyQt4 ChangeLog that there has been added support for Qt4.2 classes recently. I couldn't wait for official release, downloaded the latest snapshot to see if we can move on with Python bindings for QGIS. Sure we can!

First just a small note: everything mentioned here applies only to branch called Lib_Refactoring-branch in SVN which currently serves as my playground with new technologies :-)

I've started to work on python bindings for QGIS already back in april this year. But that time I've encountered a big problem: PyQt4 didn't wrap Qt3 support classes, nor Qt4 equivalents for QCanvas (used by map canvas) have been available. But nowadays we have replacement of QCanvas called QGraphicsView in Qt4.2. Since the latest PyQt4 snapshots contain support for new Qt4.2 classes there's no excuse for not having wrapped the GUI library.

In fact once you get used to it, wrapping classes with SIP is easy and quite fast - the GUI library is now completely wrapped (well, there are only 13 classes - CORE library is much bigger). The updated list of wrapped classes is located on wiki (the classes marked with a checkmark on the right). So let's look at the new possibilities:

  • create GIS applications in Python - yes, now you can create your own applications which will use QGIS libraries just with Python and no C++ code! To prove it I've ported some of Tim's tutorials. Take a look at the complete tutorial 5 in python.
  • automate some tasks in QGIS - with python console embedded in QGIS that can access map canvas you're able to enter any python commands to make some tasks easier and more automatic.
  • plugins in Python - creating a plugin with python is surely much easier that doing the same in C++. Why? You don't have to recompile the plugin on every change, shorter sources and less error-prone code!

At the end let's look in the bright future of QGIS :-)
(click to see them full sized)

Python console (still needs many improvements but already usable):

Tim's tutorial 5 - completely ported to python:

But we're still not at the finish line:

  • many classes from core library are not yet wrapped
  • some functions are not yet available in wrapped classes
  • support for python plugins is missing
  • maybe some bugs in bindings
AttachmentSize
tims_tutorial_5.png96.52 KB
python_console.png99.21 KB
mainwindow.py_.txt3.65 KB

Reply

The content of this field is kept private and will not be shown publicly.