Python

Contour Lines in Qgis

What with the GSoC project and all the other general discussion about analysis tools in QGis, I got somehow sidetracked into pondering how to do contour maps in QGis. There's the hard way: writing a bunch of C++ code to implement a contouring algorithm, then hooking that into QGis and into the GUI for raster drawing properties. Ah, no.

Capturing map coordinates in a stand alone app...


For those of you striving to build some stand alone Python apps based on the QGIS Python bindings here is a quick snip for ya:

class MapCoords(object):
  def __init__(self, mainwindow):
    self.mainwindow = mainwindow
    # This one is to capture the mouse move for coordinate display
    QObject.connect(mainwindow.canvas, SIGNAL("xyCoordinates(QgsPoint&)"),
                    self.updateCoordsDisplay)
    self.latlon = QLabel("0.0 , 0.0")
    self.latlon.setFixedWidth(200)

Html Image Plugin 0.2

Since 0.9.1 there is a nice way to upload your plugin in a repository, so others can install it automagically via the Python Plugin Installer.

A couple of months ago I needed a simple Html Image Map plugin, and wrote it using the Python Plugin Interface. Fixed some bugs in it (one which made that it was not working with postgis layers).

The plugin generates an image- and accompanying html-file for an image map.

Python plugin example... Raster file info...

So there was a question on the mailing list about the existence of a plugin to capture information about the file path for a bunch of loaded rasters... similar to the info contained in a tileindex with GDAL but interactive from within QGIS.

Accessing QT constants in PyQt...


So you get an event and you want to be able to check something like whether a button press was done with the right mouse... fear not, you can access all the same constants that you are accustom to in C++ QT:

void MyClass::mousePressEvent(QMouseEvent * e)
{
  if (e->button() == Qt::RightButton)
  {
    printf("Something...")
  }
}

In Python you can do the same:

def mousePressEvent(self, event):
  if event.button() == Qt.RightButton:
    print "Something..."

Passing python vars in PyQt using SIGNAL/SLOT...


So in QT programming signals and slots are at the heart of a well formed application. In Python (using PyQt) it is not exactly obvious how to start developing your own signals and slots. Hopefully this will help...

First, when signals have no arguments things are pretty simple. Take this example:

QObject.connect(self.timer, SIGNAL("timeout()"), self.processStatus)

Writing a Renderer in Python

For my project I want to display point data in pretty colours. I have survey data for villages that record the number of cases of disease and the village population, and I want to colour according to the percentage infected. Red for high, green for low.

Introducing Quantum Navigator


It's been quite a long time since my last blog post. In the meantime I was quite busy with getting my bachelor thesis ready. It's about creation of a simple navigation system for vehicles. In case you'd be interested you can take a look at the thesis [PDF], but it's quite tough reading as it's written completely in Slovak language :-)

But the more interesting thing is that second part of the work was implementation of a routing/navigation system and I've chosen Quantum GIS and Python to do it. This implementation is now available online, it's called Quantum Navigator (guess why!) and licensed under the terms of GNU GPL.

Writing a QgsMapTool in Python

For my project I need to give the user three ways to define a rectangular area: it can be the bounding box of a layer, it can be the current view area, or it can be defined by the user drawing a rectangle. My main dialog covers the first two options with a dropdown and a push button, but the third option meant writing a map tool - in Python of course!

The code and details are downloadable from my site.

QGIS tutorials in Python

Some time ago I've started with porting Tim's tutorials posted in the blog to Python. The main reason
of doing it was to check that bindings work correctly. I thought that some people might be interested in using them so you can download them.

Syndicate content