Posted by & filed under QGIS, Web Development.

The Python bindings for QGIS introduced just before version 1.0 was released proved to be a huge boon to the development of QGIS as a popular, free alternative to proprietary vendor’s offerings. More than 100 plugins grace our plugin repository, and the ability to use Python scripting has really lowered the barrier to entry for many who would find building similar tools in C++ (the ‘native’ language of QGIS) too intimidating. Lately I have been pondering the future of QGIS 2.0. In particular my feeling is that we pretty much have the standard functionality of a desktop GIS application covered and it is time to step out of ‘emulate’ mode into ‘innovate’ mode. Not that QGIS 1.x entirely lacks innovation, but I believe there is a lot more that can be done.

At the recent developer meeting in Zurich, I had some enjoyable conversations with Andreas Neumann and others. Andreas showed off some examples of the awesome D3 javascript svg visualisation toolkit. I had seen the kit before in its former guise as protovis, but I hadn’t ever seen quite the extent of all the cool things you could do with it. Parallel to Andreas’ presentation, I had been pondering fusing web technologies with QGIS. Now let me start out by explaining that living in a low bandwidth society has made me quite cautious about building web tools for the masses, but what I am talking about here is using web technologies on the desktop without any need for an internet connection. D3 is just one example of many hundreds of javascript libraries out there that cover a whole gamut of functionality. I would argue that the javascript universe is far richer than the Qt/C++ one and far easier to ‘pick up and use’. Combined with this rich javascript resource is the fact that recent versions of Qt4 ship with QWebView, a webkit based widget that you can place onto any form. More than that, Qt4 provides entry points for calling javascript routines from C++ and passing C++ objects into the javascript context. Though I havent tested it yet, you can also use Qt4’s signal and slot mechnism from within the Javascript context.

If you take a minute to think about this, you will realize that this opens up a world of possibilities: what if we use C++ for the heavy lifting and Javascript + CSS + html for our visualisation in QGIS? Not for map rendering per se, but for all the other places where you need to see charts, tables, reports, metadata and so on. And what is really nice is that we have a fixed browser platform to work against, and complete platform independent capability, without any of the overhead that Python for example introduces (like having to ship a separate interpreter with the QGIS binaries). Plus the multitude of people that can already do web programming suddenly have an easy way to start contributing to QGIS.

To demonstrate this idea I have updated my fork of QGIS to use JQuery, Flot and some html to do the rendering of the histogram in the raster layer properties dialog. You can see a little demo of this below:

[advanced_iframe securitykey=”da39a3ee5e6b4b0d3255bfef95601890afd80709″ src=”” height=”315″ width=”560″]

While building this I noticed a couple of nice benefits:

  • I can debug my javascript separately in a browser
  • I can update the html / javascript and simply reinstall those files while QGIS is still running and immediately see the results
  • Whatever libraries I chose to use (jquery and flot in this case) were trivial to package with QGIS and I didnt need to worry about making the user e.g. install a separate python package before they could use my code
  • The code to implement the graph was much simpler than my former Qwt based implementation and it was trivial to add the zoom capability shown in the video above
  • The rendered graph looks much nicer than the Qwt one it replaces without any effort on my part
  • It was fun to work on!

And this last point is probably the most important – the more fun it is to hack on QGIS, the more likely we will get others to contribute. Hopefully we can also start attracting web innovators like my friend Javier de la Torre from Vizzuality to see QGIS as a place where they can bring the awesome stuff they are doing on the web into the desktop environment! I have quite a few other ideas as to how we can leverage this technology further so look out for further posts on the topic.