The GeoPackage format is a developing open standard with recently added support in QGIS. The GeoPackage format has the properties of both the file format and a geodatabase. It overcomes all the limitations of the shapefile format, such as file size limits, attribute name length limits, and many other inconveniences. In a single file, GeoPackages can contain multiple vector and raster datasets. Software can query the file like a database without the overhead of a database server.
Read support for GeoPackages in QGIS is robust; however, write support has some limitations. You can save a single layer to the GeoPackage format using the QgsVectorLayer
class or the Processing Toolbox. However, if you want to store multiple layers in a GeoPackage, you must use OGR directly. Fortunately, OGR is included in QGIS and available in the Python Console. In this recipe, we'll load two vector layers and save them in a single GeoPackage using OGR.