Take the 2-minute tour ×

Sorry about the strange title didn't really know how to word it.

I currently use MapInfo to do most of my GIS work however I have recently installed PostGIS 1.5 and am really liking it so far. A project that I am going to start working on in the future sometime will involve creating an application for managing stormwater assets, all my previous mapping projects have just been using a MapInfo window embedded in a C# application. Now that I have some data in a PostGIS server it has opened a lot of possibilities.

I tried writing some small sample applications using NHibernate and NHibernate.Spatial in C# but to say it's frustrating is a understatement (sometimes static typed code gives me the shits).

So I was wondering if anyone had any experience writing a Qgis plugin using python to access PostGIS and if you think it would be a viable route to take, and if so anyone had any good places to read about doing such things.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

There are a lot of python plugins for QGIS that access PostGIS. Just download them and check the source code. Accessing PostGIS from Python is quite straight forward (same is true for SpatiaLite by the way).

PostGIS related plugins by name:

  • PgQuery for QGIS
  • PostGIS Manager
  • PostGIS SQL Query Editor
  • RT Sql Layer
  • ...
share|improve this answer

I have no experience or knowledge of the QGIS API. What I know is that it is a viable approach and it can be a very rewarding experience.

You can check out PyQGIS Cook Book - that shows a lot of code on how to achieve common taks. That might help you.


share|improve this answer
Thanks for the link George, very handy indeed. –  Nathan W Aug 7 '10 at 10:23

from pyQGis cookbook:

uri = QgsDataSourceURI()


uri.setDataSource ("public ","roads ", "the _geom ", "cityid=2643 ")

vlayer=QgsVectorLayer (uri .uri() ,"layer _ name_you_ like","postgres ")
share|improve this answer

Your Answer


