39 votes
Accepted

Using GeoPackage instead of SpatiaLite, and vice-versa?

A small comparison between GeoPackage and SpatiaLite in QGIS. Right to the moment it is not really productive to use GeoPackage with QGIS. May change pretty fast though (see addtions!). Some ...
user avatar
  • 6,045
39 votes
Accepted

How do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?

To write to GeoJSON: dataframe.to_file("output.json", driver="GeoJSON") To write to GeoPackage: dataframe.to_file("output.gpkg", driver="GPKG") Documentation is here, though somewhat sparse.
user avatar
  • 6,738
26 votes

How to add another layer to GeoPackage in QGIS?

I'm seeing this years later, but if someone still wonders... In addition to the "save as" method, with QGIS 3.0, you can click and drag layers inside a GeoPackage within the Browser panel.
user avatar
24 votes
Accepted

Uploading Geopackage contents to PostgreSQL

This tutorial shows how to import geopackges into postgres with ogr2ogr like: ogr2ogr -f PostgreSQL "PG:dbname=gadm" DNK_adm.gpkg Note importing into PostgreSQL like this will convert the case of ...
user avatar
  • 1,002
19 votes
Accepted

GeoPackage in QGIS: what are .gpkg-shm and .gpkg-wal files?

As the SQLite core of a GeoPackage is a single-file based RDB, it needs to utilize temporary support structures to guarantee atomic transaction management. SQLite supports different mechanics to ...
user avatar
  • 23.9k
17 votes

Creating Spatial Index for GeoPackage using QGIS

It's possible in QGIS 3. You can click "Create Spatial index" from the Layer Properties Dialog:
user avatar
  • 26.3k
17 votes
Accepted

How to prevent gpkg size increase when I delete attributes?

** EDIT: You can now do this in the QGIS file browser by right clicking on the .gpkg and selecting vacuum ** You should VACUUM your database to reduce the size of the database after deleting rows/ ...
user avatar
  • 6,762
17 votes
Accepted

Spatialite spatial queries do not function on GeoPackage

The issue is with the way I am using Spatialite. After talking with the company behind the web service that provides these datasets (since I initially assumed it may have been an export bug), they ...
user avatar
17 votes
Accepted

Reading geopackage geometries in Python

You can use the gdal/ogr, fiona (built on gdal/ogr) or geopandas (built on fiona) python libraries. Below is a fiona example: import fiona # No need to pass "layer='etc'" if there's only one layer ...
user avatar
  • 52.8k
17 votes

Display photo stored as blob in GPKG

To display the photo stored as blob in GPKG or PostgreSQL, one simple solution is to use QGIS HTML Widget. It is a widget to be used in forms. It can be used also for a table without geometries. Add a ...
user avatar
  • 4,645
16 votes

Is there any way to include "universal" style/symbology in GeoPackage?

QGIS support its own format QML and SLD. When you use GeoPackage (or PostGIS) you can save the style on the GeoPackage and distribute both the data and the style. On the layer properties, the Style ...
user avatar
  • 4,645
16 votes
Accepted

Creating gpkg with many layers using ogr2ogr

You are overwriting dst.gpkg every time you run ogr2ogr. From the geopackage documentation: For adding new layers into existing geopackage run ogr2ogr with -update. So do: ogr2ogr -f GPKG dst....
user avatar
  • 52.8k
14 votes

Converting ArcMap feature layers to GeoPackage using

You are looking for a GP tool Create SQLite Database available since 10.4 (previously, in 10.3, you had to use an arcpy function CreateSQLiteDatabase(). Choose as spatial_type parameter GEOPACKAGE ...
user avatar
14 votes
Accepted

Writing multiple layers to GeoPackage using writeOGR() in R?

You can do this using the append flag on sf::st_write(): library(sf) nc <- st_read(system.file("shape/nc.shp", package="sf")) storms <- st_read(system.file("shape/storms_xyz.shp", package="...
user avatar
  • 1,205
14 votes

Creating geopackage from multiple raster files?

New raster tables must be added into existing GeoPackage as subdatasets as documented in the GDAL driver manual page http://www.gdal.org/drv_geopackage_raster.html. Have a look at the fifth example ...
user avatar
  • 52.5k
13 votes
Accepted

Add layer to existing geopackage not working in QGIS?

My advice is to upgrade to >=2.18.1. Version 2.18.1 introduced a feature where right clicking a layer and selecting save as, then choosing an existing gpkg file, now gives you the choice of either ...
user avatar
  • 26.3k
12 votes

Adding layers to GeoPackage using PyQGIS

You need to use QgsVectorFileWriter.writeAsVectorFormat. If you store one layer per GPKG file you just need: # get layer list by one of: #QGIS2 lyrs = iface.mapCanvas().layers() # OR lyrs = ...
user avatar
  • 377
12 votes
Accepted

What's happening with unusually large geopackage file size?

SQLite database is stored into a single file and when user does updates/deletes it is much faster just to mark the old data as removed. Nothing gets physically removed from the data file and the size ...
user avatar
  • 52.5k
12 votes

Way to restore the data in the accidentally overwritten layer by its duplicate layer in QGIS?

The original answer by @user30184: If the .wal file still exists it is possible that edits have not been written into .gpkg file yet. Copy just the .gpkg file into another directory, rename it, open ...
user avatar
11 votes
Accepted

Does GeoPackage support simultaneous editing?

I have no technical background on how Geopackage works internally, so after searching for information on the simultaneous editing capabilities of Geopackage and barely finding anything conclusive, I ...
user avatar
11 votes
Accepted

Loading QGIS project from database using PyQGIS

You can load a project from a database storage (e.g., PostgreSQL or GeoPackage) in this way: QgsProject.instance().read(uri) Where uri is the file name of the project, which you could get from: ...
user avatar
11 votes

Checking if active layer is GeoPackage using PyQGIS

You can use: if iface.activeLayer().storageType() != 'GPKG': print('Active layer is not a GeoPackage format')
user avatar
  • 1,210
11 votes
Accepted

Renaming GeoPackage layer to be the same as GeoPackage file

Try this. (You'll have to adjust it to match your exact data/situation) import os geopackage_folder = r'/home/bera/Desktop' for root, folder, files in os.walk(geopackage_folder): for file in ...
user avatar
  • 52.5k
10 votes
Accepted

Why Editing a GeoPackage table with ogr is very slow?

Make a minor but important change and make all edits to happen within one transaction instead of doing one transaction for each row. Transactions are rather expensive for SQLite and therefore also for ...
user avatar
  • 52.5k
10 votes
Accepted

Can QGIS read/load a zipped shapefile or Geopackage from a URL/URI?

Yes. Use the GDAL/OGR VSI (virtual file system) syntax. For a URI, you would use /vsicurl, for a zip you would use /vsizip and you can chain them together, for a zip URI you would use /vsizip//...
user avatar
  • 52.8k
10 votes

Reading geopackage geometries in Python

Geopandas is extremely useful and easy to use for this kind of thing: http://geopandas.org/ You can load vector data with attributes (e.g. from geopackages, shapefiles, etc.) into ?(geo)pandas ...
user avatar
  • 166
10 votes
Accepted

QGIS Geopackage export of layer symbology

The symbology is not saved at the time of export, it is saved as a default symbology afterwards. To do this go to the Layer Properties of the newly created geopackage layer, set the symbology the way ...
user avatar
  • 4,528
10 votes
Accepted

Count number of features in a geopackage and write to a file

I had done something similar with python. The script loops recursive through the directories starting from the startdir and then opens each geopackage and reads the gpkg_contents table - containing ...
user avatar
  • 7,730
9 votes

QGIS 3: How to rename attribute/field names for Geopackage Layer

You can rename, drop, add, reorder Geopackage fields using QGis 3.x as follows: Processing > Toolbox > Vector table > Refactor fields. This will output a new Geopackage.
user avatar
  • 7,371
9 votes

Rename layer in gpkg using QGIS or PyQGIS?

You can rename the tables in GeoPackage with the DB Manager Another option is to use ogrinfo with the OGR SQL dialect as documented in https://www.gdal.org/drv_geopackage.html. Usage: ogrinfo ...
user avatar
  • 52.5k

Only top scored, non community-wiki answers of a minimum length are eligible