By David Crowther
QGIS 3.8 Zanzibar was released in August 2019 and the full change log can be viewed here:
Haven’t replaced your Shapefiles with GeoPackage yet? Well here’s another reason why you should….
In QGIS 3.8, they have added the ability to store QGIS projects directly inside GeoPackage files! This means that you can create a totally self-contained GeoPackage which embeds a QGIS Project AND all the data used by the project.
Saving to GeoPackage Projects
Step 1 - Firstly, if you haven’t already got any you will need to create a GeoPackage file.
In QGIS I have opened 3 Shapefiles for 3 roads layers – ARoads, Broads and Mways.
Using the GeoPackage Layers tool you can select your 3 individual Shapefiles and save them into ONE GeoPackage file. Ensure you set the Destination GeoPackage to a name and location that you will remember – here I have chosen to name the GeoPackage – AllRoads.gpkg.
Note - This is what a GeoPackage file looks like in Windows Explorer.
Step 2 - Once the GeoPackage file has been created, to test that the GeoPackage opens you will need to create a NEW Connection to the GeoPackage file using Data Source Manager. Here we have made a connection to the AllRoads GeoPackage file and called the connection AllRoads.
Selecting all three layers in the Table window and then choosing Add will open each of the 3 datasets in the AllRoads GeoPackage into QGIS…. displaying the 3 individual layers.
Step 3 – Using the enhancement to QGIS we can now choose the Project – Save to GeoPackage option to create a Project file within the GeoPackage file.
However, before we do that we will undertake some styling, labelling and add a basemap to our project.. as per the example below.
Having now started to build a Project, we can choose to save the project settings into the GeoPackage file.
From the Project menu choose Save to GeoPackage. Choose the Connection to be the GeoPackage file that we created in Step 1, and enter a Project Name e.g. All UK Roads Styled and then press OK.
To test that the Project has been saved in the GeoPackage file, close and re-open QGIS and then from the Project menu choose Open From – GeoPackage.
Choose from the list of Connections for GeoPackage files that you may have previously created, in this case we will choose the AllRoads.gpkg file.
Then finally from the Project list choose the All Roads Styled project and then press OK.
Note – One GPKG file may contain more than one Project, which means you can style the data as many ways as required and store those settings in multiple different Projects.
QGIS will now open the Project stored within the GeoPackage file… remembering all the style changes and additional data sources e.g. OSM that were saved into the Project.
Yet another reason to ditch those Shapefiles and go truly Open Source!