[Qgis-developer] Load a Spatialite layer using python bindings

Martin Dobias wonder.sk at gmail.com
Sat Mar 27 10:56:58 EDT 2010


On Sat, Mar 27, 2010 at 6:23 AM, Marcelo Reyes <reyesmarcelo at gmail.com> wrote:
>
> Hello,
>
> I'm trying to load a vector layer from a spatialite table. It is easy to do
> it in qgis using the tool bar option, but I want to do it programatically
> using the python bindings. This is because I'm developing a small stand
> alone application.
>
> Can any one show me an example of how to to this? I've found code with
> Postgis, but none with spatialite.

uri = QgsDataSourceURI()
uri.setDatabase('/home/martin/test-2.3.sqlite')
uri.setDataSource('','Towns', 'Geometry')

v=QgsVectorLayer(uri.uri(), 'Towns', 'spatialite')

(don't forget to check v.isValid() to see whether the vector layer got
loaded correctly)

Bye
Martin


More information about the Qgis-developer mailing list