1

I have identified a need to change VRTs raster order through its order of appearance in it's respective XML file. Unfortunately this seems to not be possible to do dynamically using QGIS commands or plugins.

So I'm thinking of developing a tool that detects a change to the map canvas then gets the center coordinate, finds the rasters in the VRT that are in view then reorders them in the XML file according to how close they are to the canvas center.

This seems very simple to do but I have no idea how to do eventing in the QGIS interface. Ideally this needs to be a background job that continually runs.

Are there any tutorials out there introducing one to eventing in QGIS Python?

1

I did a little searching and found a few things that may be helpful for you concerning QGIS and events.

From the documentation (looks like only C++... should be able to take some names and figure out the python bindings though), there looks to be a class than handles when the canvas is clicked and moved. You may be able to find the python bindings that handle that.

The Building Event-Driven Plugins workshop explains some of these bindings and how QT objects use events/signals. Here is more information on the QT Signals and Slots and also on Event System for QT.

Lastly, this post describes looking for a mouse click in QGIS. Although it is dealing with a mouse click event, you should be able to get an idea of how handling is done from it.

From those sources and with a good amount of API documentation reading, you should be able to monitor the map's canvas element and use its events/signals to trigger your processes.

  • Thanks for the elaborate answer. Any ideas on the VRT application? I'm thinking I will have eventual problems writint on an xml that is being used by the VRT layer. – jhc Aug 6 '15 at 15:14
  • 1
    I don't know anything about VRT. I did a quick search on it, and it seems to be part of a virtual GDAL dataset? I am guessing you can call GDAL methods via a python handler to adjust the order in the XML. Or, if that is unavailable, you can probably create a class that will modify the XML yourself based off the schema specifications found here (svn.osgeo.org/gdal/trunk/gdal/data/gdalvrt.xsd). I am assuming if you follow the specifications, things should work fine unless there are locks or other things in place that'll prevent writing/editing of the XML document. – Branco Aug 6 '15 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.