Qgis: File System Watcher / Watchdog

Created on 9 Jan 2020  路  4Comments  路  Source: qgis/QGIS

Feature description.
I'd like for there to be a file system watcher / watchdog as part of (at least) the Geopackage driver that would detect when a geopackage has been updated/replaced by an external tool when loaded within QGIS, to facilitate the (re)load of data in the project seamlessly.

Inspired by Issue #33259 , and in response to comment #565387571.

Additional context
Would likely close/improve the below issues:

  • Show Feature Count not updating properly #29616

    • Overwrite of layer within Geopackage does not trigger updates/cleanups/maintenance as it should #29617

    • source fields list does not update when layer is overwritten #29629

Optional/Stretch
Make this type of filesystem watcher work across GDAL/MDAL/PDAL drivers so it is format agnostic! 馃槏

Feature Request

All 4 comments

@Saijin-Naib did you try with sql triggers ?

@Saijin-Naib did you try with sql triggers ?

No! I'm pretty crap with database stuff, to be completely honest. Learning as I go blindly. If I could go back in time to when I got my undergrad/grad in GIS I'd smack my advisors for not pushing DBA/SQL and Python :|

If you have your layers connected in the db manager, simply go on the info page and scroll down, there should be some triggers by default. This should give you an idea of the working syntax (each provider like things differently) , Here is some basics on trigger Pretty much use this in the sql window and if you can run it, it should work.

The only things that might be an issue are geospatial functions, often they need to rely on the spatialite extension and the extension is 'stored' in the connection. This will lead to geospatial function behaving weirdly. Though something was recently implemented in the provided when I made my PR for the SQL query dialog.

For non-database formats where triggers are not available, you can use QFileSystemWatcher
I use the following as a workaround for the broken watch file functionality on csv layers.

from PyQt5.QtCore import QFileSystemWatcher
watcher = QFileSystemWatcher()
watcher.addPath(filePath)
watchedLayer = vlayer
def reload_watched_layer():
    watchedLayer.dataProvider().forceReload()
watcher.fileChanged.connect(reload_watched_layer)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

aborruso picture aborruso  路  4Comments

NathanW2 picture NathanW2  路  3Comments

NathanW2 picture NathanW2  路  4Comments

Mariosmsk picture Mariosmsk  路  3Comments

pathmapper picture pathmapper  路  3Comments