[Qgis-developer] Multi threading and background processing

Martin Dobias wonder.sk at gmail.com
Thu Nov 21 23:23:51 PST 2013


Hi Tom

On Thu, Nov 21, 2013 at 1:01 AM, Tom Moore <moortom at gmail.com> wrote:
>
> The simulation model will take a long time to run and I don't want it to
> stall the GUI as it is performing.
> 1) Does qg support background processing?  Where can I read about the
> synchronization mechanism?  If not, what is the best way to handle this?

QGIS does not have any special support for background processing.

One side thought: seems like your computation could be done within
Processing framework (used to be SEXTANTE before QGIS 2.0). The
obvious advantage is that you just write your algorithm and register
it, all GUI for input of parameters would be done by the framework.
But I do not think it currently supports things like continual updates
of the results in canvas.


> It would be really nice to be able to have a dynamic display of the ongoing
> simulation as it is running.  I was thinking that I could use a GDAL
> in-memory driver (http://www.gdal.org/frmt_mem.html) to hold simulated
> conditions.
> 2) If I did this, could I display this type of raster in the qg map canvas?
> What kind of synchronization is required so the simulation pauses when the
> map is redrawn due to user interaction (zooming or panning for example).

You could have a dynamic display, but I am afraid it will not be very
simple / efficient.

I am not sure how could you do the dynamic display with in memory
raster - as far as I know it is not possible to pass existing GDAL
dataset to a raster layer nor get access to GDAL dataset of a raster
layer (but I have just limited knowledge about rasters in QGIS).
Probably you could use a temporary raster file for that. Also I do not
know what happens if a raster file changes while it is open as a
raster layer - whether it will pick up the changes or not (probably
depends on particular GDAL driver).

Regarding rendering of canvas - it is currently done in the main
thread, it simply iterates over all visible layers and reads data from
their providers. As mentioned above, the provider uses its own handle
to data (in your case GDAL dataset), so no synchronization is required
because the handle is not available outside of the provider (the
question is how GDAL handles external change of data of an opened
dataset).

> 3) How will I be able to signal the map canvas when it is time for an
> update?  Is QgsMapLayer.dataChanged() sufficient?   I see that someone else
> has tried this and had difficulty:
> http://article.gmane.org/gmane.comp.gis.qgis.devel/21481.  I assume that the
> problem there was that the method was stalling the event loop.  What are the
> rules for event loop interactions?

Clearing layer's cached image and calling canvas' refresh() should be enough.


> 4) Can I update my raster map layer without having to re-draw the other
> layers that may be on the the map canvas?  Does the map canvas support
> compositing?  I see that QgsMapLayer supports an image cache, but I have not
> found any explanation of how to use it.

There is a feature called render caching - when turned on (in QGIS
preferences), all layer rendered images (for particular extent) are
cached in memory, so if only one layer changes, only that one will be
redrawn.

Regards
Martin


More information about the Qgis-developer mailing list