Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
podcast
Filter by Categories
ArcGIS Pro
GDAL
GeoJson
Map
Python
QGIS
Uncategorized

Understanding GeoPackage

Understanding GeoPackage: A Comprehensive Guide to the Open Standard Format

GeoPackage is an open standard file format for storing geospatial data, which is widely used in Geographic Information Systems (GIS). It is based on SQLite database technology, which means that it is a single file format that can store different types of geospatial data, including vector data, raster data, and attribute data. GeoPackage is designed to be platform-independent and can be used on different operating systems and with different GIS software.

The format also supports advanced features such as spatial indexes and metadata, making it a versatile and efficient way to store and share geospatial data.

Want to stay ahead of the geospatial curve? listen to our podcast!

Advantages of using GeoPackage as a format for storing geospatial data:

  1. Portability: GeoPackage is a single file format that can be easily transferred between different devices, operating systems, and GIS software.
  2. Versatility: GeoPackage can store multiple types of geospatial data, including vector data, raster data, and attribute data.
  3. Efficiency: GeoPackage supports advanced features such as spatial indexes, which can improve the performance of spatial queries and data visualization.
  4. Interoperability: GeoPackage is an open standard format that is supported by many GIS software tools and platforms.
  5. Accessibility: GeoPackage files can be easily shared with others, as they are self-contained and can include styling, layouts, and metadata.
  6. Standardization: GeoPackage is an official standard of the Open Geospatial Consortium (OGC), ensuring that it is a reliable and consistent format for storing geospatial data.
Advantages of GeoPackageExplanation
PortabilityGeoPackage is a single file format that can be easily transferred between different devices, operating systems, and GIS software.
VersatilityGeoPackage can store multiple types of geospatial data, including vector data, raster data, and attribute data.
EfficiencyGeoPackage supports advanced features such as spatial indexes, which can improve the performance of spatial queries and data visualization.
InteroperabilityGeoPackage is an open standard format that is supported by many GIS software tools and platforms.
AccessibilityGeoPackage files can be easily shared with others, as they are self-contained and can include styling, layouts, and metadata.
StandardizationGeoPackage is an official standard of the Open Geospatial Consortium (OGC), ensuring that it is a reliable and consistent format for storing geospatial data.
Better support for spatial dataGeoPackage supports more advanced spatial data types than other formats, including multi-geometry types and spatial indexes.
Larger file size limitsGeoPackage can handle much larger files than some other formats.
Better attribute data managementGeoPackage has better support for managing attribute data than some other formats, including support for non-ASCII characters and attribute domains.
FlexibilityGeoPackage can store multiple types of geospatial data, including vector data, raster data, and attribute data.

How to create a geopackage

Create a GeoPackage in QGIS by following these steps:

  1. Open QGIS and create a new project or open an existing one.
  2. In the Layers panel, click the “Create a new layer” button to create a new vector layer, or right-click on an existing layer and choose “Export” to export it to a new GeoPackage file.
  3. In the “Create a Layer” or “Export” dialog box, choose “GeoPackage” as the file format.
  4. Choose a name for the GeoPackage file and a location to save it.
  5. Choose the type of data you want to store in the GeoPackage, such as point, line, or polygon data.
  6. Define the properties of the new layer, such as the name, attributes, and coordinate system.
  7. Add data to the new layer by importing or creating new features, or by loading data from other sources.
  8. Save the changes to the GeoPackage by choosing the option to save or export the layer to the GeoPackage format.

You can also create a new GeoPackage file without creating a new layer by going to the “Browser” panel, right-clicking on a folder, and choosing “New GeoPackage”. Then you can add new layers to the GeoPackage by right-clicking on it and choosing “New Layer”.

Create a GeoPackage file using Python and the GDAL/OGR library

Here’s an example script that creates a new GeoPackage file and adds a point feature to it:

import ogr

# Define the name and location of the new GeoPackage file
filename = "new_data.gpkg"
driver = ogr.GetDriverByName("GPKG")
data_source = driver.CreateDataSource(filename)

# Define the spatial reference system for the data
srs = ogr.osr.SpatialReference()
srs.ImportFromEPSG(4326)

# Create a new point layer in the GeoPackage file
layer_name = "points"
layer = data_source.CreateLayer(layer_name, srs, ogr.wkbPoint)

# Define the attributes for the point layer
field_name = ogr.FieldDefn("name", ogr.OFTString)
field_name.SetWidth(50)
layer.CreateField(field_name)

# Create a new point feature in the layer
point = ogr.Geometry(ogr.wkbPoint)
point.AddPoint(0.0, 0.0)
feature = ogr.Feature(layer.GetLayerDefn())
feature.SetGeometry(point)
feature.SetField("name", "my point")
layer.CreateFeature(feature)

# Close the GeoPackage file
data_source = None

This script uses the ogr module from the GDAL library to create a new GeoPackage file, create a point layer, add attributes to the layer, create a new point feature, and save the changes to the file. You can modify this script to create other types of layers, add more features, or define different attribute fields as needed.

Create a GeoPackage file in R using the sf package

Here’s an example code snippet that creates a new GeoPackage file and adds a point feature to it:

library(sf)

# Define the name and location of the new GeoPackage file
filename <- "new_data.gpkg"

# Create a new point feature
point <- st_point(c(0, 0))
names(point) <- "name"
point$name <- "my point"

# Define the attributes for the point layer
attributes <- st_drop_geometry(point)

# Define the spatial reference system for the data
crs <- st_crs(4326)

# Create a new GeoPackage file and add a point layer to it
data_source <- st_write(attributes, dsn = filename, layer = "points", driver = "GPKG", crs = crs)

# Close the GeoPackage file
st_close(data_source)

This code uses the sf package to create a new GeoPackage file, add a point feature to it and define the attributes and spatial reference system for the data. You can modify this code to create other types of layers, add more features, or define different attribute fields as needed. Note that sf uses the OGR library in the background, which is the same library used by GDAL and QGIS.

Can I include styling information in a GeoPackage file?

Yes!, you can include styling information in a GeoPackage file. The GeoPackage format supports storing symbology and styling information in addition to vector and raster data. This means that when you save a vector layer with styling information to a GeoPackage file, the symbology is stored with the layer and can be accessed when the layer is opened in another GIS software that supports the format.

To save the styling information for a vector layer in QGIS, you can do the following:

  1. Right-click on the layer in the “Layers” panel and select “Properties”.
  2. In the “Layer Properties” dialog, select the “Symbology” tab.
  3. Choose the symbology type you want to save, such as “Single symbol” or “Categorized”.
  4. Configure the symbology settings as desired.
  5. Click on the “Style” button to open the “Style Manager” dialog.
  6. In the “Style Manager” dialog, click on the “Save Style…” button.
  7. Choose the GeoPackage file you want to save the style to and click “OK”.
  8. In the “Save Style” dialog, give the style a name and click “OK”.

Once you have saved the styling information for a vector layer to a GeoPackage file, the symbology is stored with the layer and can be accessed when the layer is opened in another GIS software that supports the format.

About the Author
I'm Daniel O'Donohue, the voice and creator behind The MapScaping Podcast ( A podcast for the geospatial community ). With a professional background as a geospatial specialist, I've spent years harnessing the power of spatial to unravel the complexities of our world, one layer at a time.

Leave a Reply