3

With an CSV layer Qgis workspace [loaded as a delimited text layer], an external algorithm is ran; outputting (writing) new values to certain rows in the layers source CSV file.

The writing works properly (CSV can be opened in text editor immediately after ext. process to show the correct values in question), yet a problem arises in the Qgis updates. The changed values; when viewed in the attribute table depict a 'NULL' value.

Although removing and reloading the layer properly updates the attribute table, I would like to avoid such; as important temp. display-label data / settings needs to be retained.[Possibly the only option?]

I have tested the following scripts without resolve:

            csvDelimTextLayer.reload()
            csvDelimTextLayer.updateFields()
            iface.legendInterface().refreshLayerSymbology(csvDelimTextLayer)
            iface.mapCanvas().refresh()

Spending some more time revealed the following work-flow:

-The algorithm which updates the CSV is activated

<p>-The updates only show a 'NULL' value in the attribute table</p>

<p>-Immediately after confirming 'NULL's, save project and close QGIS</p>

<p>-Upon reopening the QGIS and the project, the proper data is displayed.  Additionally (and perhaps most importantly) now every time the algorithm is ran - the reflected changes (and values) are properly viewable in the attribute table without having to resave and restart QGis.</p>

Does this indicate an error or missing step in my initial method of allocating data in PyQgis when writing and loading the CSV; which upon saving and restarting QGis is fulfilled?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Katalpa
  • 871
  • 10
  • 20
  • Please carify: Is the CSV loaded using add delimited text provider or using add vector layer = OGR? – underdark Jan 10 '15 at 15:02
  • Edited to reflect the loaded file type (delimited text) – Katalpa Jan 10 '15 at 15:05
  • Is the best (or only) option to; after calculations are made - remove the layer from the Qgis-Legend, then reload the layer from the updated data source? – Katalpa Jan 11 '15 at 13:31
  • @Katalpa, have a look at this post: http://gis.stackexchange.com/questions/64722/how-to-update-data-from-external-table-in-real-time – Germán Carrillo Feb 16 '15 at 21:43
  • 1
    @gcarrillo - outstanding tip. Allot cleaner then the current solution. – Katalpa Feb 17 '15 at 12:48
  • @Katalpa Right, I wonder why reloading layer sources is not documented anywhere. There is a reload method that doesn't seem to work. Anyways, that's the solution. – Germán Carrillo Feb 17 '15 at 12:51

0 Answers0