Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

For my own data analysis pipeline, I am running a split screen setup with iPython notebooks on one side, generating variables from source data, pushing them to a csv file which qgis then reads/joins to an appropriate geography, instantly visible on the other side of the screen.

I would like to push the control of the running instance of qgis to the ipython notebook, in effect allowing a super quick calculation/visualization cycle. Right now I can do this in the qgis python console with something like this:

canvas = qgis.utils.iface.mapCanvas()
cLayer = canvas.currentLayer()
canvas.refresh() 

but I would like to:

  1. connect to an existing instance of qgis from an external python environment
  2. at a minimum refresh the map, after each re-write to the csv from ipython notebook, but preferably
  3. re-calculate breaks (using quantiles, natural breaks) based on the newly joined values

Any pointers appreciated!

share|improve this question

migrated from stackoverflow.com Nov 18 '13 at 5:58

This question came from our site for professional and enthusiast programmers.

1  
This is going to be a lot tricker than you might think. First of all, process security will ensure that a process that doesn't want to be controlled can't be controlled by another process. QGIS would have to provide a well-defined IPC interface, or use something like D-Bus to allow other processes to interact with it. The next question is, how would that tie into the QGIS user interface? If you're in edit mode for a layer in QGIS, and trigger an update from your notebook, what happens in QGIS? –  Lukas Graf Nov 17 '13 at 20:00
1  
What I imagine could work is writing a QGIS plugin that reads the CSV, and does all the refreshing and recalculating you need it to do, and bind that to a shortcut like F5. On the other side in the IPython notebook, write a function that saves your data to the CSV and make sure that function will always get imported into your global namespace, by using the PYTHONSTARTUP environment variable for example. –  Lukas Graf Nov 17 '13 at 20:05
    
Indeed, I had not thought about all the conflicts that could entail. So this approach would 'drive' the ipython stuff from qgis, not the other way around, but that is clearly a way to Rome. –  ako Nov 17 '13 at 20:33
1  
No, my suggestion was to not make the update fully automatic. Bind reload to a quick shortcut like F5 in QGIS, and save to a simple function in notebook. Still two actions, but should nevertheless speed up your cycle. A one button solution would be possible I guess, but considerably more complex, and you'd need to be willing to invest quite some time into it. –  Lukas Graf Nov 17 '13 at 21:36
1  
Turns out, IPython provides some very useful features for IPC: Communication between an IPython Kernel and an interactive interpreter like the notebook follows a decoupled two-process model. Also, messaging between kernel and client is well specified and documented, and uses ZeroMQ. So you could probably leverage that, and talk to the IPython kernel from a QGIS plugin (via ZMQ). Still a lot of work though. –  Lukas Graf Nov 17 '13 at 21:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.