Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

QGIS plugin reference

The GeoPackage Toolkit plugin for QGIS: its data provider and its Processing algorithms. To install it, see How to install the QGIS plugin and add a layer through it.

Requirements

QGIS3.28 or later
Plugin repositoryhttps://urschrei.github.io/geopackage/qgis/plugins.xml
Release zipsgpkg_toolkit-<version>.zip, attached to each plugin release, tagged qgis-plugin-v<version>, on GitHub
Changelogqgis-plugin/CHANGELOG.md
StatusExperimental

The zip holds compiled code for each platform it supports. A file is chosen when the plugin loads.

Platformgeopackage_rs moduleNative provider
Linux x86_64 (glibc 2.28 or later)yesQGIS 4.0, 4.2
Linux aarch64 (glibc 2.28 or later)yesQGIS 4.0, 4.2
macOS (arm64 and x86_64)yesQGIS 4.0, 4.2
Windows x86_64yesQGIS 4.0, 4.2

On Linux and macOS, both use the SQLite that QGIS has loaded. On Windows, each has its own.

Data provider

Provider keygeopackage_rs
URI/path/to/file.gpkg|layername=<table>, as OGR’s. Without layername, the file’s only layer or attribute table.
LayersFeature layers and attribute tables
OpenedLeniently: DATETIME text in the common ISO 8601 forms other than GeoPackage’s own is read

Implementations

The key is served by one of two implementations. They give the same results.

ImplementationServes the key when
Native (Rust behind a C++ shim, geopackage-qgis)QGIS 4, and the plugin has a build for the running minor version
Python (gpkg_toolkit/data_provider.py)Otherwise, including every QGIS 3

The GeoPackage Toolkit tab of the Log Messages panel names the implementation in use, and why the native one isn’t used.

Environment variableEffect
GPKG_TOOLKIT_NATIVE_PROVIDER=<path>Loads the native build at <path> instead of the one in the plugin
GPKG_TOOLKIT_NATIVE_PROVIDER=0Uses the Python implementation

Reads

QGIS requestHow the provider serves it
Bounding boxThe layer’s RTree, then QGIS’s exact-intersection test when asked
One feature id, or severalfid = <id>, or fid IN (...)
Subset stringAn SQLite WHERE clause, as in OGR. An invalid one is rejected when it is set
Attributes without geometryA column projection: unread columns and geometry are not fetched
Filter expressionEvaluated by QGIS on the rows read
Destination CRS, limit, order by, distance withinAs QGIS’s core providers serve them

Edits

CapabilitySupported
Add, delete featuresYes
Change attribute values, geometriesYes
Add, delete, rename fieldsNo

Each edit call is one transaction. A geometry is converted to the column’s type, as multi, and given or stripped of Z and M, on the way in. A commit writes through the library, which keeps the spatial index and the extent up to date.

Algorithms

Each algorithm’s identifier is gpkgtoolkit:<name>. An algorithm that opens a GeoPackage opens it leniently.

Validate GeoPackage (validate)

Group: Inspect and repair. Read-only.

ParameterTypeDescription
INPUTFile (.gpkg)The GeoPackage
OUTPUTTableFindings

Fields of OUTPUT: severity (error, warning or advisory), code, table_name, message, repair, plugin_algorithm, the name of the algorithm here that makes the repair.

Outputs: ERRORS, WARNINGS, ADVISORIES, the number of findings of each severity. The findings are this library’s checks, not the OGC test suite’s.

Repair spatial indexes (repairspatialindexes)

Group: Inspect and repair. Modifies the file.

ParameterTypeDescription
INPUTFile (.gpkg)The GeoPackage
LAYERString, optionalOne layer; every feature layer if empty
BUILD_MISSINGBoolean, default falseBuild an index for a layer that has none
OUTPUTTableIndex report

Fields of OUTPUT: layer, status_before and status_after (current, legacy, stale or absent), action, missing, extra.

Output: REPAIRED, the number of layers changed.

A legacy (pre-1.4 or mixed) or stale trigger set is replaced with the 1.4 triggers and the index is rebuilt; the action is rebuilt with 1.4 triggers. An index that is out of step with its table is rebuilt (rebuilt), and with BUILD_MISSING, an absent one is built (built). Otherwise the action is none.

Repair geometry and datetime encodings (repairencodings)

Group: Inspect and repair. Modifies the file.

ParameterTypeDescription
INPUTFile (.gpkg)The GeoPackage
LAYERString, optionalOne layer or attribute table; all if empty
OUTPUTTableRepair report

Fields of OUTPUT: layer, geometries and datetimes, the number of values rewritten.

Output: REPAIRED, the number of tables changed.

A geometry whose WKB gives Z or M by a high-bit flag in a type code is rewritten with ISO type codes and a header envelope. DATETIME text in another ISO 8601 form is rewritten in the GeoPackage form, unless that would lose precision. See How to repair geometry and datetime encodings.

List extensions (listextensions)

Group: Inspect and repair. Read-only.

ParameterTypeDescription
INPUTFile (.gpkg)The GeoPackage
OUTPUTTableExtensions

Fields of OUTPUT: name, table_name, column_name, scope, support, definition. support is implemented, known (recognised, not implemented; writes to a table it covers are refused when its scope is read-write), removed (withdrawn from the standard) or unrecognised.

Sample coverage at points (samplecoverage)

Group: Coverages. Read-only.

ParameterTypeDescription
INPUTFile (.gpkg)The GeoPackage
COVERAGEString, optionalThe coverage; the file’s only one if empty
POINTSPoint layerThe points to sample, transformed into the coverage’s CRS
ZOOMInteger, optionalThe zoom level; the most detailed if empty
INTERPOLATIONnearest (default) or bilinear
FIELDString, default valueThe name of the new field
OUTPUTPoint layerThe points, with the new field

A point outside the coverage, in a tile the coverage does not store, or on a null sample gets NULL. A multipart or non-point geometry is sampled at its centroid. On a grid-value-is-area coverage, bilinear gives the same values as nearest.

Coverage tile statistics (coveragestatistics)

Group: Coverages. Read-only.

ParameterTypeDescription
INPUTFile (.gpkg)The GeoPackage
COVERAGEString, optionalThe coverage; the file’s only one if empty
ZOOMInteger, optionalThe zoom level; the most detailed if empty
OUTPUTPolygon layerOne footprint per stored tile

Fields of OUTPUT: coverage, zoom, tile_column, tile_row; the statistics recorded in gpkg_2d_gridded_tile_ancillary, rec_min, rec_max, rec_mean, rec_std_dev; the statistics calculated from the decoded samples after scale and offset, without null samples, min, max, mean, std_dev, count; and error, why a tile could not be decoded.

Find NaN and infinite values in coverages (checkcoveragesamples)

Group: Coverages. Read-only.

ParameterTypeDescription
INPUTFile (.gpkg)The GeoPackage
COVERAGEString, optionalThe coverage; every coverage if empty
OUTPUTPolygon layerThe outline of each failing tile, in the coverage’s CRS

Fields of OUTPUT: coverage, zoom, tile_column, tile_row, message.

Output: FAILURES, the number of failing tiles.

A tile fails when it contains a NaN or infinite value, which the GeoPackage standard does not allow in a coverage (Requirement 21), or when it cannot be read. Validate GeoPackage reads only the header of each tile, so it does not make this check.

Export layer to GeoPackage (exportlayer)

Group: Import and export.

ParameterTypeDescription
INPUTVector layerThe layer to write
OUTPUTFile (.gpkg)A new file, or an existing one to add a table to
LAYER_NAMEString, optionalThe table’s name; the input’s name if empty
SPATIAL_INDEXBoolean, default trueBuild a spatial index

Outputs: OUTPUT_LAYER, the written layer; WRITTEN, the number of rows.

The table is a GeoPackage 1.4 table with the 1.4 trigger set, and the index is built in bulk. An integer field named fid gives the feature ids; otherwise they are assigned. A field type with no GeoPackage equivalent is written as TEXT. A single geometry in a multi layer is written as multi. The CRS is added from the EPSG registry when it has an EPSG code, and from its WKT otherwise.

Plugins → GeoPackage Toolkit:

EntryEffect
Add GeoPackage layer with this pluginAsks for a file and a layer, and adds the layer through geopackage_rs
Each algorithm, in the toolbox’s groupsOpens the algorithm’s dialog

The menu has no entries when the geopackage_rs module does not load. The GeoPackage Toolkit tab of the Log Messages panel gives the reason.