[Qgis-user] code running inside QGis, failing outside

Alexander Bruy alexander.bruy at gmail.com
Fri Oct 19 04:56:11 PDT 2012


Hi,

looks like you didn't initialize QGIS. See PyQGIS CookBook [0]

[0] http://www.qgis.org/pyqgis-cookbook/intro.html#python-applications

2012/10/19 PIERRE Sylvain <sylvain.pierre at cg67.fr>:
> Hello list,
>
> The following code is running perfectly inside Qgis (1.7.2) from the python
> console :
>
> from PyQt4 import QtCore, QtGui
> uri = QgsDataSourceURI()
> uri.setDatabase( "C:/APPLI_PDT/CANAL_DEV/bd_canal.sqlite")
> uri.setDataSource( "", "AOT_POINT", "GEOMETRY" )
> layer = QgsVectorLayer( uri.uri(), "AOT", "spatialite" )
> provider = layer.dataProvider()
> feat = QgsFeature()
> geometry = QgsGeometry()
> feat.setAttributeMap({1:QtCore.QVariant(5)})
> feat.setGeometry(geometry.fromPoint(QgsPoint(990650,110807)))
>  (res, outFeats) = provider.addFeatures( [ feat ] )
> print str(res)
>
> But outside it’s failing (in my app build with python, PyQt and PyQgis).
>
> Res is set to false, and no row was insert.
>
> I’ve spent lots of time with Google, but didn’t found anything…

-- 
Alexander Bruy



More information about the Qgis-user mailing list