GeoPackage

Overview

GeoPackage (.gpkg) is an Open Geospatial Consortium (OGC) standard for storing geospatial information in a self-contained SQLite database. It supports both vector features and raster tile data in a single portable file, making it the modern replacement for Shapefile.

Key Features

FeatureDescription
Single FileAll data in one .gpkg file
SQLite-basedStandard SQL queries work
Vector + RasterSupports both data types
No Size LimitUnlike 2GB Shapefile limit
Full Field NamesNo 10-character limit
Multiple CRSDifferent projections per layer
Null ValuesProper NULL support

Advantages Over Shapefile

AspectGeoPackageShapefile
File count13-7+
Size limitNone2 GB
Field names128 chars10 chars
Geometry typesMultiple per layerSingle
Coordinate systemsMultipleSingle
NULL valuesYesNo
Date/time fieldsYesLimited

Structure

GeoPackage contains standard SQLite tables:

TableDescription
gpkg_contentsCatalog of contents
gpkg_spatial_ref_sysCoordinate reference systems
gpkg_geometry_columnsGeometry column metadata
gpkg_tile_matrixTile matrix definitions
gpkg_tile_matrix_setTile extent and CRS

Usage Examples

GDAL/OGR

# convert shapefile to geopackage
ogr2ogr -f GPKG output.gpkg input.shp
 
# convert multiple shapefiles to layers
ogr2ogr -f GPKG output.gpkg input1.shp
ogr2ogr -f GPKG -update output.gpkg input2.shp
 
# query with SQL
ogrinfo output.gpkg -sql "SELECT * FROM layer WHERE area > 1000"

R

library(sf)
 
# read geopackage
parcels <- sf::st_read("data.gpkg", layer = "parcels")
 
# write geopackage
sf::st_write(parcels, "output.gpkg", layer = "parcels")
 
# list layers
sf::st_layers("data.gpkg")

Python

import geopandas as gpd
 
# read
gdf = gpd.read_file("data.gpkg", layer="parcels")
 
# write
gdf.to_file("output.gpkg", layer="parcels", driver="GPKG")

SQLite Direct Access

-- connect with sqlite3 and load spatialite
.load mod_spatialite
 
-- query features
SELECT * FROM parcels WHERE ST_Area(geom) > 10000;

When to Use

Choose GeoPackage when:

  • Desktop GIS workflows (QGIS, ArcGIS)
  • Data exchange between systems
  • Archival storage
  • Need multiple layers in one file
  • Replacing Shapefiles

Consider alternatives when:


Appendix

Created: 2024-12-23 | Modified: 2024-12-23

See Also


(c) No Clocks, LLC | 2024