Getting Started With OGC GeoPackage

Wherelytics
3 min readAug 16, 2018

--

GeoPackage is an open format OGC standard for geospatial data. Based on sqlite database container with a .gpkg extension for storing vector, raster and tile caches inter-operable across mobile , desktop and server.

Creating a GeoPackage

You can create a new GeoPackage by importing existing data such as a Shapefile, MapInfo TAB file using most of today’s popular GIS softwares such as ESRI ArcGIS, MapInfo Professional or opensource GIS such as QGIS or GDAL. GDAL provides a simple command line for importing existing vector, raster data using OGR utilities

Example — Importing shapefile into GeoPackage using OGR

ogr2ogr -f GPKG countries.gpkg countries.shp

Opening a Geopackage

Using any of the popular GIS Desktop softwares such as ArcGIS, MapInfo Professional or QGIS one can manage GeoPackage data. Current GeoPackage supported software’s can be found here.

What’s inside

GeoPackage contains a number of tables as defined by the OGC standard grouped into metadata and user defined tables. As per specifications the following metadata tables are expected gpkg_contents, gpkg_spatial_ref_sys and gpkg_geometry_columns tables.

Metadata tables

gpkg_contents — List all of geospatial contents in a GeoPackage.

gpkg_spatial_ref_sys — Contains coordinate reference system definitions that are referenced by contents listed in gpkg_contents and gpkg_geometry_columns tables.

gpkg_geometry_columns — Describes the geometry for a particular table containing features. This table holds a corresponding row for each feature table contained in a GeoPackage.

User-defined Data Tables

Features (Geometry along with Attributes) are stored in user-defined data tables. Each features table has exactly one geometry column in a BLOB format. The geometry types supported are as defined in the OGC Simple Features. Apart from the geometry column and a primary key, the schema of a feature table can consists of other columns with sqlite supported data types.

Vector Metadata tables

Raster Tiles

The GeoPackage stores raster data in tile pyramids consisting of tiles of different spatial extent and resolution at different zoom levels, and the tile data itself. The “Tile” is termed as a single raster image such as a PNG or JPEG that covers a specific geographic bounds. The “Tile matrix” consists of rows and columns of tiles having the same spatial bounds and resolution for a particular zoom level. The “Tile matrix set” is based on the model as specified in the OGC WMTS Implementation Specification.

Example — Importing raster file into GeoPackage using GDAL

gdal_translate -of countries.tif countries_raster.gpkg -co RASTER_TABLE=countries

The main difference to vector data in GeoPackage raster tiles are addition of two additional metadata tables, gpkg_tile_matrix_set and gpkg_tile_matrix. In addition to these tables, each tile pyramid consists of a user-defined table that contains the actual tiles. By default, tile zoom levels are generated by powers of two, but custom zoom levels are allowed. The raster tiles are stored in user data tables as PNG and JPEG unless a custom extension is used.

Raster Tiles metadata

Extensions

GeoPackage provides a mechanism to support features that are not part of the core standard using a custom GeoPackage extension. The RTree Spatial Indexes Extension is such an extension that adds capability to index geometry columns using the rtree implementation provided by the SQLite R*Tree Module extension. The spatial index is established by creating a virtual table (rtree_countries_geom) and a set of triggers.

RTree Index tables and triggers

There has been a lot of interesting activity around GeoPackage lately with good adoption by various leading GIS vendors. GeoPackage holds a good future specially useful for disconnected mobile usage. Check out Wherelytics future blogs around GeoPackage in coming months.

Originally published at medium.com on August 16, 2018.

--

--