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.

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
add comment

3 Answers

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
add comment

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.

http://www.mapserver.sk/~wonder/qgis/html/

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

from pyQGis cookbook:

uri = QgsDataSourceURI()

#set host name, port , database name, username and password
uri.setConnection("localhost ","5432 " , " dbname"," johny","xxx ")

#set database schema, table name, geometry column and optionaly subset(WHERE clause)
uri.setDataSource ("public ","roads ", "the _geom ", "cityid=2643 ")

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

Your Answer

 
discard

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

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