[Qgis-developer] Re: Load SQLite table into QGIS

Martin Dobias wonder.sk at gmail.com
Fri Oct 14 16:22:50 EDT 2011


On Fri, Oct 14, 2011 at 4:33 PM, mmekuria <sailmcm at yahoo.com> wrote:
> I have made a few changes here and I do not get a valid layer in the first
> place.
>
>
>        QgsDataSourceURI splUri;
>        splUri.setDatabase(spliteDBName);  // i give the database name as a
> fully qualified path QString
>        splUri.setDataSource("","Trips", ""); // I set the schema and the
> geometry to empty? I have a table Trips in the database.

Unfortunately currently this does not work correctly for goemetryless
tables (the produced URI is malformed), therefore I advise you to
directly create URI string as mentioned in my earlier mail:

vlayer = QgsVectorLayer('dbname="/data/gis/test.sqlite"
table="mytable"', 'mytable', 'spatialite')


>        tripLayer->addFeatures(tripFeats);
>        bool blnFeat = tripLayer->commitChanges();

Here I would suggest to use directly tripProv->addFeatures( ... )
instead of using layer's addFeatures() method. This way you will
bypass layer's in-memory editing buffer and the operation will be
faster. I would like to explain the difference in the cookbook,
hopefully it will be added soon.

Martin


More information about the Qgis-developer mailing list