TransWikia.com

Load a table with NO geometry_column using PyQGIS

Geographic Information Systems Asked by aurel_nc on January 12, 2021

I had to backup a PostGIS model in a geopackage and I wonder how to load a non-spatial table, aka a table with NO geometry_column.

One Answer

Just had to write None instead of the geometry_column name in the setDataSource method.

uri = QgsDataSourceUri()
uri.setConnection("MyServerAdress", "5432", "myBase", "user", "pass")
uri.setDataSource(schema, table, None)
layer = QgsVectorLayer(uri.uri(False), table, "postgres")
QgsProject.instance().addMapLayer(layer)

Correct answer by aurel_nc on January 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP