TransWikia.com

Accessing existing instance of QGIS in stand-alone Python script

Geographic Information Systems Asked on April 28, 2021

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

How can I achieve this?

2 Answers

QGIS conda-forge package should be handy

Answered by Enock4seth on April 28, 2021

I don't know if this will help but in the ArcGIS land you can attach a debugger to an existing python process with Visual Studio. I know you are running on QGIS and I haven't tried, but you may be able to follow the same steps to attach Visual Studio to your QGIS Session.

In this documentation it describes how to hook up Visual Studio and the Pro Version of PyCharm. Also the Visual Studio link for how to attach to a python debugging process.

You basically start Visual Studio (not Vs Code) and make sure the Python Development is installed then you attach your debug to hopefully your QGIS instance. It may not work but it could be worth a shot.

From ArcGIS Docs Attach Python Debugger

Answered by Ben on April 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP