[Qgis-developer] Updating a layer when data changes

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Fri Aug 28 08:10:43 PDT 2015


I'm trying to make a layer redraw when the underlying data changes.
This seemed to work well in 2.8 but is very unreliable in 2.10.

I am trying to do the following:

 * create a point shapefile (from R) with a 'z' attribute having
values between 0 and 1
 * load into qgis, use a graduated renderer to colour points according to z
 * overwrite the shapefile with the same points but z set to 0.9 for all points
 *  *** wave magic wand *** points are now coloured for z=0.9 (dark blue)
 * overwrite the shapefile with the same points but z set to 0.1 for all points
 * *** wave magic wand *** points are now coloured for z=0.1 (white)


The trouble is the magic wand waving. Assorted StackOverflow posts and
mailing list threads point at:

 layer.triggerRepaint()
 layer.setCacheImage(None)
 layer.dataProvider().dataChanged.emit()

none, or all, of which seem to update the visible layer. Not even if I
drag and zoom a bit. Although sometimes, after a while doing nothing,
it updates. I can't figure out what's triggering it, and I'm fairly
sure the first two of the above worked well in 2.8 (have upgraded all
my 2.8s to 2.10s now...).

 I've deselected "Use render caching..." in the Rendering tab of the
Options dialog.

 The only reliable way of updating a layer I've found is to
right-click on the legend and "Duplicate", and then the duplicate
layer and the original both get drawn using the new z values from the
updated on-disk shapefile after toggling the legend visibility.

 So, I'm stuck. Apologies for cross-posting to GIS.SE:

http://gis.stackexchange.com/questions/159950/make-a-qgis-layer-update-from-a-changed-data-source

but you might want to comment/answer there if you crack it.

Version details follow, running on Linux Mint 17:

QGIS version 2.10.1-Pisa
QGIS code revision exported
Compiled against Qt 4.8.6
Running against Qt 4.8.6
Compiled against GDAL/OGR 1.10.1
Running against GDAL/OGR 1.10.1
Compiled against GEOS 3.4.2-CAPI-1.8.2
Running against GEOS 3.4.2-CAPI-1.8.2 r3921
PostgreSQL Client Version 9.3.4
SpatiaLite Version 4.1.1
QWT Version 5.2.3
PROJ.4 Version 480
QScintilla2 Version 2.8.1

thanks

Barry


More information about the Qgis-developer mailing list