qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.43k stars 2.99k forks source link

File System Watcher / Watchdog #33690

Open Saijin-Naib opened 4 years ago

Saijin-Naib commented 4 years ago

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:

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

roya0045 commented 4 years ago

@Saijin-Naib did you try with sql triggers ?

Saijin-Naib commented 4 years ago

@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 :|

roya0045 commented 4 years ago

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.

uclaros commented 4 years ago

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)