Guides ·

What is a GeoPackage (.gpkg) and how to open it

Someone sent you a .gpkg file and your computer has no idea what to do with it. A GeoPackage is a map data format, and under the hood it is a small database in a single file. This guide explains what is inside one, why GIS teams like it, and how to open it in QGIS, in a database tool or in your browser, using the world's countries, cities, rivers and lakes from Natural Earth.

Drop your .gpkg into the free unmake GeoPackage viewer to see every layer, its attributes and its coordinate system.Try it on your own file
The unmake GeoPackage viewer with natural-earth-world.gpkg: a world map with countries, cities, rivers and lakes, 457 features in 4 layers, and the layer list with countries (177 multipolygons) and cities (243 points) in WGS 84
natural-earth-world.gpkg in the GeoPackage viewer, layers in their own colours. Made with Natural Earth data (public domain); map © OpenStreetMap contributors.

One file, one database

GeoPackage is an open standard published by the Open Geospatial Consortium (OGC), the body behind many map formats. The standard defines a GeoPackage as a platform-independent SQLite database file. SQLite is a small, widely used database engine whose databases are ordinary single files.

The standard adds a few rules on top. The file must end in .gpkg. Its header carries the code GPKG, so programs can tell it apart from any other SQLite file. Open one in a text editor and the first 16 bytes read SQLite format 3.

That means you can look inside a GeoPackage with any SQLite tool, such as the sqlite3 command-line program or DB Browser for SQLite, even without map software.

What is inside

A GeoPackage is a set of tables. A few of them, with names starting with gpkg_, describe the file. gpkg_contents lists every layer: its name, whether it holds features or image tiles, its extent and its coordinate system. gpkg_spatial_ref_sys holds the coordinate systems themselves, each with an ID and a full definition. gpkg_geometry_columns says which column holds the shapes and what type they are.

Then each layer is a table of its own: one row per feature, one column for the geometry, and one column per attribute. The geometry is stored as a small binary blob: a header starting with the letters GP, followed by the shape in the standard well-known binary format.

Because each layer declares its own coordinate system, one file can hold layers in different systems side by side.

A GeoPackage is one SQLite file: gpkg_contents lists the layers, gpkg_spatial_ref_sys holds coordinate systems, and each layer (countries, cities, rivers, lakes) is a table
Inside natural-earth-world.gpkg: two of the gpkg_ tables that describe the file, and one table per layer.

What a GeoPackage can hold

According to geopackage.org, a GeoPackage can carry vector features (points, lines and polygons with attributes), tile sets of imagery and raster maps, plain tables without geometry, and extensions, which add more, such as extra metadata.

Most files you receive hold vector layers. Raster tiles are less common and need a desktop GIS or a viewer that supports them.

Why people send GeoPackages

One file is easier to send than a folder of matching files, and it cannot lose a piece on the way. Many layers fit in that one file. Attribute columns have real types, such as whole numbers, decimals, text and dates, and field names can be as long as you like, so population_estimate stays population_estimate.

The format is also a living standard: the current version is 1.4.0.

How to open a GeoPackage

In QGIS, the free desktop GIS, drag the .gpkg onto the map window. Programs built on the GDAL library, which many GIS tools use, can read it too.

To peek at the tables, open it in an SQLite tool. The query SELECT table_name, data_type, srs_id FROM gpkg_contents; lists the layers in a second.

Without installing anything, the unmake GeoPackage viewer opens it in the browser. Each feature layer gets its own colour on the map, the panel lists the layers with their feature counts and coordinate systems, and a table shows the attributes, layer by layer. Its page says it reads vector layers only (not raster tiles or curved geometries) and that files over about 1 GB need a desktop GIS.

The attribute table of the countries layer: columns fid, name, continent, population_estimate and iso_a3, with Fiji, Tanzania, Canada and other countries
The countries layer in the viewer's table. Long field names such as population_estimate are kept. Data: Natural Earth (public domain).

A worked example: the world in one GeoPackage

  1. We made natural-earth-world.gpkg from Natural Earth's 1:110 million data, which is public domain: four layers called countries, cities, rivers and lakes, all in WGS 84. The file is 315,392 bytes.
  2. In a terminal, sqlite3 natural-earth-world.gpkg ".tables" lists seven tables: gpkg_contents, gpkg_geometry_columns, gpkg_spatial_ref_sys and the four layers. The gpkg_contents query returns four rows, each with data_type features and srs_id 4326.
  3. Drop the file into the GeoPackage viewer. The panel reads 457 features in 4 layers, and the map shows country outlines, cities as dots, rivers and lakes in their own colours.
  4. Open Details: countries has 177 multipolygons, cities 243 points, rivers 13 multilines and lakes 24 multipolygons, each in WGS 84 (EPSG:4326), read from the file. Details shows the file size as 308 KB.
  5. Open the table (More, then Table) and pick countries from the layer menu. The columns are fid, name, continent, population_estimate and iso_a3: the 19-character field name arrives whole.
  6. Press Convert to see the formats on offer: GeoJSON, KML, KMZ, GPX, CSV, Shapefile, GeoPackage and FlatGeobuf. Use it when a colleague's software cannot read .gpkg.

Common mistakes

Questions

Is a GeoPackage the same as an SQLite database?

It is an SQLite database that follows the OGC rules: the gpkg_ tables, the GPKG code in the header and the .gpkg file name ending.

Can I open a GeoPackage in Excel?

Not directly. Convert a layer to CSV first, then open the CSV in Excel.

Which GeoPackage version is current?

Version 1.4.0, adopted by the OGC. Files from earlier versions are still GeoPackages.

How can I tell which version a GeoPackage is?

Run PRAGMA user_version; in an SQLite tool. Our demo file returns 10300, which means version 1.3.0.

Sample file: natural-earth-world.gpkg (four layers made by unmake from Natural Earth 1:110m data) · public domain data (Natural Earth); file put together by unmake

Sources

Drop your .gpkg into the free unmake GeoPackage viewer to see every layer, its attributes and its coordinate system.Try it on your own file