2

I'm new to pyqgis/python and programming in general.. and i am working on my first small project. I want to create plugin so that I can add layers from my PostGIS database to a QGIS project.

I suppose I need to create a list with my layers and the connection parameters to QGIS and populate the combobox with the list. I am not sure how to go about it, are there someone willing to give me some pointers?

Best regards

3
  • For code related questions you should first post in your question what you have tried. Have you created the plugin opening the Qt form and combo control yet?
    – artwork21
    Commented Dec 21, 2015 at 15:55
  • Sorry if it was unclear. Yes I have created the frame for the plugin and enabled the plugin in QGIS with a combo box. So I need to fill in the relevant code.
    – geogrow
    Commented Dec 21, 2015 at 16:44
  • Did my answer help you solve your question? If so, please mark the answer as accepted, as indicated here gis.stackexchange.com/tour Commented Nov 6, 2016 at 0:16

1 Answer 1

3

First of all, do you really need a plugin for that? QGIS already offers you the 'Add PostGIS Layer' button as well as the 'DB Manager' plugin. Both of them allow you to load PostGIS layers to QGIS.

In case that you definitely want to achieve what you asked, have a look at this post about loading PostGIS layers to a PyQGIS standalone application (in Spanish). It can help you understand how to connect to PostGIS and how to populate a comboBox with your database layers (using Python).

You will also find useful the official QGIS documentation on Developing Python Plugins.

1
  • Thanks for the advice, I will go through the blogpost you attached. I need to build a pluging because I have a few hundred tables and the plugin will help non GIS users to easy access relevant layers for a project.
    – geogrow
    Commented Dec 21, 2015 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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