3

I would like to add layers into a spatialite database. I have used the QgsVectorFileWriter method:

parcDisSHP='/xxx/xxx/xxx/xxx/FILE.shp'
parcelasDis = QgsVectorLayer(parcDisSHP, 'Parcelas_Unicas', "ogr")
QgsVectorFileWriter.writeAsVectorFormat(parcelasDis, "/xxx/xxx/xxx/xxx/database.sqlite", "utf-8", None, "SQLite", False, None ,["SPATIALITE=YES"])

But this method it seems good for create the database and insert just one layer. If I repeat the operation for other layers, this rewrites the Database again.

What should I do to add more layers to this DB?

Is there some others ways to do this operation?

Joseph
76.7k8 gold badges173 silver badges286 bronze badges
asked Jun 20, 2016 at 16:28

1 Answer 1

2

I will reply myself. This is not a direct aproach, but a workaround that it works:

import subprocess
subprocess.call(["spatialite_tool", "-i", "-shp", "/xxxx/xxxxx/xxxxx/xxxxx/PARCELA_xxxxx", "-d", "/home/xxx/xxxx/xxxxx/villar.sqlite", "-t", "Parcelas", "-g", "Geometry", "-c", "UTF-8","-s","3042", "--type", "MULTIPOLYGON"])
answered Jun 23, 2016 at 13:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.