[Qgis-user] Python Console and python scripts geoprocessing in QGIS

Martin Dobias wonder.sk at gmail.com
Thu Jan 14 03:36:08 PST 2010


Hi Noli

On Thu, Jan 14, 2010 at 2:04 AM, Noli Sicad <nsicad at gmail.com> wrote:
> [...]
>
> Did anybody manage to use qgis in python?
>
> from PyQt4.QtCore import *
> from qgis.core import *
>

Do you mean to run python scripts from command line that would use
functionality of QGIS libraries? It's possible to do it and many times
very useful. I've written several such scripts for various uses, e.g.
map rendering or aligning points with street numbers to network of
streets. It's also possible to create interactive applications using
QGIS gui library where you can use map canvas with just few lines of
code (see [1]).


> I think it would be useful if some of the authors of those python
> plugins can demonstrate how to use the functions / commands in python
> script in QGIS python console or just in python CLI. We can mix and
> match command for geoprocessing to unless the power of QGIS. I know
> what can R GEO can do.

As Carson have already written, there are barely any plugins which
would have good support of interaction from QGIS python console
(although I admit it would be very useful). It depends how well is the
plugin code split into 'core' and 'gui' part: having core code bounded
tightly with the gui would make it hard to use plugin's functionality
from console. Second problem is that probably not many plugin
developers are willing to keep some code compatibility among different
versions to ensure that potential users don't have to change the code
with new versions.

Anyway, just a small example how the plugins can be accessed (PostGIS
Manager plugin is used and prints DB server info):
>>> pm = qgis.utils.plugins['postgis_manager']
>>> pm.dlg.db.get_info()
u'PostgreSQL 8.3.8 on x86_64-pc-linux-gnu, compiled by GCC
gcc-4.4.real (Ubuntu 4.4.1-3ubuntu3) 4.4.1'

Of course the plugin must be started first. Btw. this works for QGIS
>= 1.4. For QGIS <= 1.3 the first command would be:
>>> pm = plugins['postgis_manager']


[1] http://blog.qgis.org/node/59

Regards
Martin



More information about the Qgis-user mailing list