With the help of Stack Exchange I have been able to set up a PyCharm environment in which I am able to run QGIS geo-processing queries, so away from the Python console in QGIS itself. If I point to the directories in which my shapefiles or geopackages are located I can fairly easily access those and generate outputs to an output directory of my choice.

However, I would like to be able to access geospatial tables directly from a PostgreSQL/PostGIS database and use the QGIS based processing libraries to run analyses involving these datasets. I have been trying to find a way to achieve this using

  • the psycopg2 python library ..and/or
  • a PostGisDBConnector function that some posts suggest used to work prior to QGIS 3.10 and now seems not to work

In fairness, I am experimenting and haven't found any solution yet. Effectively I want to find a way of essentially pointing to, for example, a line feature layer in the PostgreSQL DB and to a polygon layer such that I get a URI for both that I can then use in the parameters of a processing function such as qgis:intersection.

At the moment I cannot find a method or appropriate syntax to achieve this. Has anyone out there tried to do similar with QGIS 3.14 and Python 3?

  • Have a look at the cookbook (go to the PostGIS section): docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/… There you find how to build the URI or create the vector layer for a PostGIS layer source. Aug 18 '20 at 23:10
  • Thanks German. I had missed that in the cookbook. I need to learn to look in there more often prior to randomly searching the internet
    – TrevP
    Aug 19 '20 at 10:07
  • Yes, it's good to skim it at least once, so that you know what you can find there. It's a very handy documentation resource. Aug 19 '20 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.