[Qgis-developer] postgres getFeatures segfault in pyqgis not in console
Richard Duivenvoorde
rdmailings at duif.net
Wed Feb 4 08:07:48 PST 2015
A question raised on IRC:
The following code after setting the right PYTHONPATH and
LD_LIBRARY_PATH runs fine for a shapefile,
OR for a postgres table IN THE PYTHON CONSOLE(!)
But if you run the code in a terminal, it segfaults?!
Anybody a clue?
Trying to attach gdb to the so libs, but failing.
It segfaults at the getFeatures() call, as if something wrong with the
iterator..
Regards,
Richard Duivenvoorde
#! /usr/bin/python
# -*- coding: utf8 -*-
from qgis.core import *
import qgis.utils
QgsApplication.setPrefixPath('PATH_TO_QGIS', True)
QgsApplication.initQgis()
db = QgsDataSourceURI()
db.setConnection('host', '5432', 'dbname', 'dbowner', 'pass')
db.setDataSource('public', 'dbtable', 'dbcolumn_geom')
vlayer = QgsVectorLayer(db.uri(), 'test', 'postgres')
#below is just working
#vlayer = QgsVectorLayer("PATH_TO_SHAPE", "test", "ogr")
print vlayer
print vlayer.featureCount() # ok 12
print vlayer.isValid() # ok: True
features = vlayer.getFeatures() # SEGFAULT
for feature in features:
print 'fid ', feature.id()
More information about the Qgis-developer
mailing list