Skip to content

Read geopackage (.gpkg) geographic data

Jan Kristian Jensen edited this page May 11, 2022 · 5 revisions

Geopackage is a modern, ligth weight and popular format for geographical data, mantained by the Open Geospatial Consortium. A geopackage file is a sqlite database file with some special tables, so any tool with sqlite support can read geopackage (*.gpkg) files. For visidata, simply append the --filetype sqlite argument like so:

vd FILENAME.gpkg --filetype sqlite

Don't let all the other tables confuse you

Below is a screen shot opening a geopackage file containing one single table, named myInterestingData. All other tables are geographical metadata and indexes. These are nescessary to extend a regular sqlite file into a geopackage file. Most tools with geopackage support will hide these tables from the end user.

image

Any table starting with gpkg, rtree*, rtree*, trigger* and the table sqlite_sequence do NOT contain the tabular data you're looking for, and should be ignored (unless you have a curious mind and want to poke around). In that case, the table geopackage_contents may be a good place to start poking.

Here's a screenshot of actual tabular data. The first two columns, fid# and geom, are the geopackage primary key and geometry, which is all binary and therefore just look like noise in visidata. All other columns contains the actual tabular data you're looking for, i.e. the properties of all the geographic features in that table.

image

Writing data - you probably shouldn't

We highly recomend to us another tool such as QGIS for editing geopackage files.

The bold and the brave may attempt a careful editing of existing rows and columns, which in theory should work just fine as long as you don't touch the primary key (fid) or geometry (geom) columns. Changing geometry or inserting new rows would require a solid understanding of how to encode geometry as well known binary, and avoiding all the pit falls (correct geometry type, correct coordinate system and so on). You will also need to read the geopackage documentation for details on how to update those other tables with indexes and such, which again will require some understanding about r-tree geographical indexing.

Clone this wiki locally