Creating a spatial database

Creating a spatial database in QGIS is a simple task to perform. QGIS comes with two spatial database types that can be easily created without the need to install or set up anything.

SpatialLite and GeoPackages are relational databases that are stored as flat files. What this means is that the data is stored within a single file and not on traditional server-based database applications such as Oracle or Postgres/PostGIS.

We will be dealing with GeoPackages in this chapter, which is an OGC compliant GeoSpatial format. It is open source format and is consumed by most GIS packages, including ESRI, MapInfo, and QGIS.

SpatiaLite ( SQLite) is built on a single-user architecture, which makes the 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.

Click on Layer | CreateLayer | New GeoPackage Layer. Alternatively, in the Browser panel, right-click on GeoPackage and choose Create Database. Both options bring you to the same window:

  1. In the New GeoPackage Layer window, click on the Browse button at the end of the label database and browse to a location where you want to store your GeoPackage
  2. Give the GeoPackage a database name, for example, New_Sites
  3. Click on OK and you will come back to the New GeoPackage Layer window
  4. Set the Table name and set the value to proposed_sites
When creating a new GeoPackage/Database, QGIS will automatically give the Table name as that of the name of the GeoPackage. So, be sure to change the name of the table otherwise you might get confused. It is a good database practice not to give databases, schema, or table names the same name. 
  1. Set the Geometry type to Polygon
We will apply good database conventions by replacing all spaces between words with underscores. This is generally seen as a best practice for table names in databases. Furthermore, it is not advisable to start tables with numbers. The simple reason for this is that it makes writing SQL statements and generally managing your data within a database a lot easier.
  1. Set the EPSG to 27700 'British National Grid' (if you are doing the follow along exercises): To do this, click on the globe icon at the end of the drop-down menu and filter on 27700
  1. In a new field, create the following columns and leave these as Text data types:
    • site_name
    • reference_number
    • land_release_date
    • proposed_construction_date
    • proposal_type
  2. Click on OK to create the GeoPackage

We'll revisit New_Sites.gpkg later in this chapter.