<div dir="ltr"><div class="gmail_extra"><div class="gmail_extra">Answer:</div><div class="gmail_extra"><br></div><div class="gmail_extra">vlayer = QgsVectorLayer('track.shp', 'layer_name_you_like', 'ogr')</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">error_msg = ''</div><div class="gmail_extra"><br></div><div class="gmail_extra">error = QgsVectorFileWriter.writeAsVectorFormat( vlayer, 'test.sqlite', 'System', vlayer.crs(), 'SQLite', False, error_msg, [ "SPATIALITE=YES" , ] )</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">where:</div><div class="gmail_extra"><br></div><div class="gmail_extra">vlayer => vector layer which will be exported to spatialite</div>
<div class="gmail_extra">'test.sqlite' => absolute path to new spatialite database file</div><div class="gmail_extra">'System' => string that represents the file encoding</div>
<div class="gmail_extra">vlayer.crs() => vector layer crs</div><div class="gmail_extra">'SQLite' => provider name</div><div class="gmail_extra">False => export onlySelected?</div>
<div class="gmail_extra">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)</div><div class="gmail_extra">[ "SPATIALITE=YES" , ] => database options. (here is the trick)</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Also, there is a class <a href="http://www.qgis.org/api/classQgsVectorLayerImport.html">http://www.qgis.org/api/classQgsVectorLayerImport.html</a><br>
</div><div class="gmail_extra"><br></div><div class="gmail_extra">But, I didn't have success in create an empty database using the QgsVectorLayerImport. I think that class (QgsVectorLayerImport) expects a created spatialite database.</div>
</div><div class="gmail_extra"><div><br></div>-- <br>Daniel Vaz
</div></div>