[Qgis-developer] Creating a spatialite layer in a python plugin
Daniel
danielvaz at gmail.com
Mon Jul 15 10:19:53 PDT 2013
Answer:
vlayer = QgsVectorLayer('track.shp', 'layer_name_you_like', 'ogr')
error_msg = ''
error = QgsVectorFileWriter.writeAsVectorFormat( vlayer, 'test.sqlite',
'System', vlayer.crs(), 'SQLite', False, error_msg, [ "SPATIALITE=YES" , ] )
where:
vlayer => vector layer which will be exported
to spatialite
'test.sqlite' => absolute path to new spatialite
database file
'System' => string that represents the file
encoding
vlayer.crs() => vector layer crs
'SQLite' => provider name
False => export onlySelected?
error_msg => if there is any error message will be
put in that variable (if user don't care about error handling, set to None)
[ "SPATIALITE=YES" , ] => database options. (here is the trick)
Also, there is a class
http://www.qgis.org/api/classQgsVectorLayerImport.html
But, I didn't have success in create an empty database using the
QgsVectorLayerImport. I think that class (QgsVectorLayerImport) expects a
created spatialite database.
--
Daniel Vaz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20130715/2f034175/attachment.html>
More information about the Qgis-developer
mailing list