QGIS – Saving Multiple Layers to SpatiaLite Database

qgisspatialite

Each time I save a layer from QGIS as a spatialite it insists on creating a new db ( if you select a existing db you are asked whether to cancel or replace).

I want to package all the layers of a project into a single spatialite db for distribution.

I figure that I can use native sqlite tools to combine the layers from the individual files but it would be nice not to have to do so.

Best Answer

You can create an empty SpatiaLite database using Layer > Create Layer > New SpatiaLite Layer. Once you've done so, it will appear in the DB Manager (an included plugin; enable from the plugin manager if it is disabled). Alternatively, if you have an existing database you would like to add layers to, add it with Layer > Add Layer > Add Spatialite Layer (not with Add Vector Layer). This will make the SpatiaLite database appear in the DB Manager

Once you have done either of the above, you can use the DB Manager to import any layer loaded in QGIS, of any origin, to the SpatiaLite DB.

I believe this to be a better option than using Qspatialite, as DB Manager is a core QGIS plugin and maintained by the QGIS team.

Related Question