Hello, welcome to QGIS Tutorial. Today we are going to learn about Spatialite database. QGIS supports several databases such as PostGIS (PostgreSQL), MySQL, Oracle and Microsoft SQL Server. But, today we are going to discuss Spatialite. The robust database server such as PostgreSQL provides multiple users access at the same time. This type of database is good for a large organization where many users are working simultaneously. Spatialite is a lightweight file format that is great to store an entire spatial database in a single file. Basically, there are many similarities between Spatialite and PostGIS. Both have the same principle and technique to handle the spatial database. But both have different purposes depends on how we want to manage our spatial database.
Our Goals
In the end, by following the steps in this article, you will learn how to manage and handle the Spatialite databases on QGIS. Also, you will be able to export an existing layer to Spatialite format.
Requirements
We highly recommend you to install the latest version of QGIS. By the time I write this article, QGIS version 3.2 is available for download. Visit the download page to obtain the binary for your operating system.
Lesson 1. How to Create a new Spatialite Database on QGIS
There are several ways to create a new Spatialite database. First, we can use the Browser panel to create a new Spatialite database.
- Right-click Spatialite from the Browser panel.
- Select Create Database
- Specify where you want to save the Spatialite database. After you create the new file, you should see your new Spatialite database in the Browser panel, right below the Spatialite entry.
- If not, right-click Spatialite and then choose New Connection. Browse to the file we created from the previous step.
At this point, we have a new Spatialite database ready. Let’s continue to create a new Spatialite layer. On the following example, we are going to create a new layer, a Spatialite layer.
- Go to Layer | Create Layer | New Spatialite Layer
- On the New Spatialite Layer window, select the Spatialite database we created before.
- Give the new layer name
- Select the geometry, for example multiline. You can choose one based on the type of the data you want to include in the layer.
- Select the projection for the new layer
- Add new field as required
- Click OK
Now you can start editing the new layer.
After you create the new Spatialite layer, you will see this layer under the Spatialite database in the Browser. For example:
To open the layer, you can simply drag and drop it to QGIS canvas. Or, right-click the layer and choose Add selected layer to Canvas.
Lesson 2. How to Export a Layer to Spatialite Database
In the previous lesson, we learned how to create a new Spatialite database on QGIS and also create a new Spatialite layer. In this lesson, we are going to export an existing layer to Spatialite database. So here, we are not going to create a new layer. Imagine if we already have a shapefile layer, and we want to export it to Spatialite database.
Export Existing Layer to Spatialite Database
- Open the layer or add the layer to QGIS canvas
- Go to the Layer menu and then select Save as
- On the “Save Vector layer as” window, choose Spatialite format.
- Browse to the Spatialite database file we created earlier
- Type the layer name
- Specify the projection when needed.
- Modify some other options such as the layer’s extent and some other options
- Click OK.
In a few moments, your new layer should be exported to Spatialite format. You can check from the Browser panel.
Conclusion
Spatialite is a handy, lightweight spatial database that works very well with QGIS. We can add many vector layers to a Spatialite database, and then you can send it to your clients. Thank you for reading this article and see you in the next GIS tutorial.