
Creating a spatial database
Creating a spatial database in QGIS is a simple operation. QGIS supports PostGIS, SpatiaLite, MSSQL, SQL Anywhere, and Oracle Spatial databases. We will cover SpatiaLite, an open source project that is cross-platform, simple, and lightweight, and provides quite a bit of functionality. SpatiaLite is a spatial database management system (DBMS) built on top of SQLite, a lightweight personal DBMS.
Note
SpatiaLite (and thus, SQLite) is built on a personal architecture, which makes installation and management virtually nonexistent. The trade-off, however, is that it neither does a good job of supporting multiple concurrent connections nor does it support a client-server architecture. For a more complex DBMS, PostGIS is an excellent open source option.
We will create a new SpatiaLite database that we will use for the remaining exercises in this chapter; to do this, perform the following steps:
- Open QGIS Desktop and open the Browser panel. If the Browser panel is missing, click on Browser by navigating to View | Panels. In the Browser panel, you will find the SpatiaLite entry below your hard drive folders.
- Create a new SpatiaLite database by right-clicking on SpatiaLite and then choose Create database… (as shown in the following screenshot).
- Create a new folder on disk and save the new database as
GiffordPinchot.sqlite
. The newly created database will appear under the SpatiaLite database entry.
Now that we have a new SpatiaLite database, let's look at its initial structure and contents. To do this, we will use DB Manager, a built-in QGIS plugin. DB Manager provides a simple graphical interface to manage PostGIS and SpatiaLite databases. Using DB Manager, we will be able to view and manage our SpatiaLite database. Let's start by getting familiar with the DB Manager interface.
- Click on DB Manager under Database to open the DB Manager. The DB Manager interface (as shown in the following screenshot) is composed of four parts: menu bar, toolbar, tree view, and information panel.
- Navigate to SpatiaLite | GiffordPinochet.sqlite to see a tree listing of all tables, views, and general information about the database, as shown in in the following screenshot:
When a new SpatiaLite database is created, it is automatically populated with multiple tables and views. These tables and views hold records used by the DBMS to manage the structure and operation of the database. You should not modify or delete these tables or views unless you are absolutely sure of what you are doing.