eyecatch

Create and Convert Data with GeoPackage

Published: Last updated:
This article uses QGIS 3.34. The current LTR is 3.44.

What you'll learn


  • The features of the GeoPackage format and how to use it
  • How to create a new GeoPackage
  • Steps for converting existing data to GeoPackage

Recommended for


  • Anyone who wants to manage data efficiently in QGIS
  • Anyone who wants to handle multiple layers in a single file

Introduction

GeoPackage is a file format for vector data. In QGIS, GeoPackage has been the default file format since the QGIS 3 series. It is a newer data format that fixes the shortcomings of Shapefile: for example, it can store multiple layers in a single file and handle large datasets.

This article explains how to use GeoPackage in QGIS and what makes it convenient.

What is GeoPackage?

GeoPackage (GPKG) is a format for storing geospatial data, built on SQLite, a database management system. It is a standard format developed by the Open Geospatial Consortium (OGC), and a versatile one designed specifically for GIS and geographic data.

The official GeoPackage website, run by the OGC, collects the latest news, guidance, and frequently asked questions.

GeoPackage official website
Source: GeoPackage official website

GeoPackage has the following main advantages.

Combine multiple layers in one file
GeoPackage can store vector and raster data together in a single file. This makes it easy to organize project data and cuts down the work of managing many files.

GeoPackage can also save the style information you set in QGIS (symbols, labels, and so on). When you share the data with other users or environments, the layers keep the same look.

Handle large datasets
Compared with other file formats, GeoPackage can handle large amounts of geographic data. It can store data on the scale of several gigabytes, so it works well for large projects too.

High compatibility
GeoPackage follows the OGC standard, so many GIS applications, including QGIS, can read it. This makes it easy to exchange data between different systems.

Create a layer using GeoPackage

This section shows how to create a new layer in GeoPackage format.

Create a GeoPackage file

From the menu bar, choose Layer → Create Layer → New GeoPackage Layer.

Select New GeoPackage Layer
Select New GeoPackage Layer

The New GeoPackage Layer dialog opens. Use the top of the dialog to set basic items such as the save location and geometry type. The database and the table name are separate items here. A GeoPackage can hold multiple layers, so it helps to think of the database as a folder name and the table name as the layer name.

This example creates a GeoPackage file named data.gpkg and a point layer named point inside it. For the layer's coordinate reference system (CRS), select EPSG:4326 - WGS 84, a latitude and longitude CRS.

  1. Click the ... button and specify the save location and file name for the GeoPackage.
  2. Enter the table name. QGIS fills in the file name you entered, but enter a name that suits the layer.
  3. Select the geometry type. Here, select Point.
  4. Select the CRS of the layer. Click the globe button and choose the CRS.
Set basic items such as the GeoPackage save location and geometry type
Set basic items such as the GeoPackage save location and geometry type

This example creates a point layer. To create a line layer, select LineString. To create a polygon layer, select Polygon.

The geometry type options
The geometry type options

Next, set up the attribute data under New Field. You can add attributes later, but if you already know which ones you need, it is a good idea to set them here. This example adds a text attribute named name.

  1. Enter the field name.
  2. Select a suitable data type.
  3. Click Add to Fields List.
  4. The attribute appears in the Fields List with the settings you entered.
Set the attributes of the GeoPackage
Set the attributes of the GeoPackage

When all the settings are done, click OK.

Click OK when the settings are complete
Click OK when the settings are complete

The GeoPackage file is created in the location you specified.

The GeoPackage file is created in the specified location
The GeoPackage file is created in the specified location

The layer is also added to QGIS.

The GeoPackage layer you created is added to QGIS
The GeoPackage layer you created is added to QGIS

The point layer you just created is empty, so its attribute table does not contain any features yet.

The layer is empty, so it contains no features
The layer is empty, so it contains no features

Create features

Creating features is covered in a separate article, so this section gives only a brief overview of the steps for adding points to the point layer.

  1. In the Layers panel, select the layer you want to create features in.
  2. Click the Toggle Editing button.
  3. Click the Add Point Feature button.
Steps for creating a feature
Steps for creating a feature

After these steps, the cursor on the map canvas changes to a crosshair. Click on the map canvas in this state to create a point.

  1. Click where you want to create the feature.
  2. A dialog for entering attribute values opens. Enter the values as needed and click the OK button.
  3. The point is created.
Click where you want to create a feature and enter its attributes to create it
Click where you want to create a feature and enter its attributes to create it

When you finish editing, click the Save Layer Edits button to finalize your edits.

Click Save Layer Edits to finalize the edits
Click Save Layer Edits to finalize the edits

Convert existing vector data to GeoPackage

You can easily convert vector layers in QGIS, such as Shapefile layers, to GeoPackage.

Convert with the export function

Normally, you convert a data format with the export function.

In the Layers panel, right-click the layer you want to convert to GeoPackage, then click Export → Save Features As.

Click Export → Save Features As
Click Export → Save Features As

The Save Vector Layer as dialog opens. This example adds the 世界地図 (world map) vector layer to the data.gpkg file created above.

  1. For Format, select GeoPackage.
  2. Click the ... button to the right of File name and specify the save location and file name for the GeoPackage. This example selects an existing GeoPackage, but you can also create a new one.
  3. Enter the layer name.
  4. Click the OK button.
Set the conversion options in the Save Vector Layer as dialog
Set the conversion options in the Save Vector Layer as dialog

QGIS adds the converted layer data_世界地図. Check that the conversion worked: right-click the layer in the Layers panel, open the layer properties, and click the Information tab.

The source shows that the layer was added to data.gpkg.

The layer properties confirm that the layer was converted to GeoPackage
The layer properties confirm that the layer was converted to GeoPackage

Convert from the Browser panel

Next, here is how to convert a layer from the Browser panel. First, connect to an existing GeoPackage in the Browser panel.

In the Browser panel, right-click GeoPackage and click New Connection.

Right-click GeoPackage and click New Connection
Right-click GeoPackage and click New Connection

The Open GeoPackage dialog opens. Select an existing GeoPackage and click Open.

Select an existing GeoPackage and click Open
Select an existing GeoPackage and click Open

In the Browser panel, data.gpkg now appears under GeoPackage. If you expand data.gpkg, you can also see the layers stored in this GeoPackage.

data.gpkg appears in the Browser panel
data.gpkg appears in the Browser panel

With the connection in place, converting to GeoPackage is easy. Drag the layer you want to convert from the Layers panel and drop it onto data.gpkg in the Browser panel.

The world map layer is now added to data.gpkg.

Drag and drop a layer onto the GeoPackage in the Browser panel to convert it
Drag and drop a layer onto the GeoPackage in the Browser panel to convert it

To add the converted GeoPackage layer to QGIS, right-click the layer and click Add Layer to Project, or drag and drop the layer onto the map canvas.

Click Add Layer to Project to add the layer
Click Add Layer to Project to add the layer

Conclusion

GeoPackage is a very convenient format for managing and sharing data in QGIS. Compared with Shapefile, it offers many advantages, such as combining multiple layers in one file and handling large datasets. Try GeoPackage to make your work in QGIS smoother.

About the author
QGIS LAB Editorial Team
QGIS LAB Editorial Team

QGIS LAB is a comprehensive information hub for QGIS, the open-source GIS software. Under the concept of “Geospatial for Greater Good,” we share the knowledge and skills to open up the world through location data.