Skip to main content
deleted 2 characters in body
Source Link
exodehm
  • 949
  • 7
  • 18

I have found the answer reading the QGIS API

There areThis is the method:

void QgsDataSourceURI::setKeyColumn (QString column ) 

this is my example:

uri = QgsDataSourceURI() uri.setConnection('localhost', '5432', '-mydatabase-', '-myowner-', '-mypasswd-') uri.setDataSource('public', 'parcelas', 'the_geom') #public: schema, parcelas: the view, the_geom: spatial column uri.setKeyColumn('id') #name of my primary key vlayer = QgsVectorLayer(uri.uri(), '-name_of_the_layer-', 'postgres') if vlayer: print "All Ok!" QgsMapLayerRegistry.instance().addMapLayer(vlayer) 

I have found the answer reading the QGIS API

There are the method:

void QgsDataSourceURI::setKeyColumn (QString column ) 

this is my example:

uri = QgsDataSourceURI() uri.setConnection('localhost', '5432', '-mydatabase-', '-myowner-', '-mypasswd-') uri.setDataSource('public', 'parcelas', 'the_geom') #public: schema, parcelas: the view, the_geom: spatial column uri.setKeyColumn('id') #name of my primary key vlayer = QgsVectorLayer(uri.uri(), '-name_of_the_layer-', 'postgres') if vlayer: print "All Ok!" QgsMapLayerRegistry.instance().addMapLayer(vlayer) 

I have found the answer reading the QGIS API

This is the method:

void QgsDataSourceURI::setKeyColumn (QString column ) 

this is my example:

uri = QgsDataSourceURI() uri.setConnection('localhost', '5432', '-mydatabase-', '-myowner-', '-mypasswd-') uri.setDataSource('public', 'parcelas', 'the_geom') #public: schema, parcelas: the view, the_geom: spatial column uri.setKeyColumn('id') #name of my primary key vlayer = QgsVectorLayer(uri.uri(), '-name_of_the_layer-', 'postgres') if vlayer: print "All Ok!" QgsMapLayerRegistry.instance().addMapLayer(vlayer) 
Source Link
exodehm
  • 949
  • 7
  • 18

I have found the answer reading the QGIS API

There are the method:

void QgsDataSourceURI::setKeyColumn (QString column ) 

this is my example:

uri = QgsDataSourceURI() uri.setConnection('localhost', '5432', '-mydatabase-', '-myowner-', '-mypasswd-') uri.setDataSource('public', 'parcelas', 'the_geom') #public: schema, parcelas: the view, the_geom: spatial column uri.setKeyColumn('id') #name of my primary key vlayer = QgsVectorLayer(uri.uri(), '-name_of_the_layer-', 'postgres') if vlayer: print "All Ok!" QgsMapLayerRegistry.instance().addMapLayer(vlayer)