Skip to main content
51 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.
toms's user avatar
  • 7,058
44 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 ...
Matte's user avatar
  • 6,265
33 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 ...
Mazu_R's user avatar
  • 1,162
30 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.
Nat Azodnem's user avatar
27 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 ...
jgrocha's user avatar
  • 5,465
25 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 ...
geozelot's user avatar
  • 30.6k
24 votes
Accepted

Unique constraint failed error when saving GeoPackage in QGIS

The short answer: how to solve the problem There are at least three possibilities (screenshot for solution 1 and 2 at the bottom): In the export/save dialog, expand Select fields to export and their ...
Babel's user avatar
  • 73.8k
22 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/ ...
Zoltan's user avatar
  • 7,420
21 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 ...
user2856's user avatar
  • 67.8k
20 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:
ndawson's user avatar
  • 27.8k
18 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 ...
alphabetasoup's user avatar
17 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 ...
jgrocha's user avatar
  • 5,465
17 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....
user2856's user avatar
  • 67.8k
16 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 ...
sbphd's user avatar
  • 236
15 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="...
jsta's user avatar
  • 1,355
15 votes
Accepted

ogr2ogr write multiple layers to one geopackage

You have different SQL statements, so you can't do one single line. You can do mutiple statements like this: ogr2ogr -f "GPKG" your_gpkg.gpkg PG:"host=localhost dbname=etienne user=postgres password=...
etrimaille's user avatar
  • 7,368
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 ...
Alex Tereshenkov's user avatar
14 votes

Adding layer to GeoPackage using PyQGIS

You need to use QgsVectorFileWriter.writeAsVectorFormat. If you store one layer per GPKG file you just need: QGIS 3: # imports from qgis.utils import iface from qgis.core import QgsProject, ...
user19291's user avatar
  • 405
14 votes

Deleting entry of GeoPackage

In the browser panel, browse to the Geopackage and expand it. Right click the layer you want to delete and select Delete layer.
Babel's user avatar
  • 73.8k
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 ...
ndawson's user avatar
  • 27.8k
13 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 ...
user30184's user avatar
  • 68k
13 votes

Adding layer to GeoPackage using PyQGIS

Write a layer to a GeoPackage The easiest way to save a vector layer to GeoPackage is to use the "Save vector features to file" algorithm, available from QGIS 3.16 on. import processing ...
Germán Carrillo's user avatar
13 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 ...
TeddyTedTed's user avatar
  • 6,190
13 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 ...
user30184's user avatar
  • 68k
12 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 ...
Jorge Toledo's user avatar
12 votes

Renaming attribute/field names for GeoPackage layer in QGIS

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.
klewis's user avatar
  • 7,495
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 ...
blackcanopus's user avatar
12 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 ...
Bera's user avatar
  • 76.2k
12 votes
Accepted

Meaning of maximum field length of 0 for GeoPackage in QGIS

If you create a GeoPackage table by setting a max length for an attribute then the corresponding SQL CREATE statement will look like this: CREATE TABLE "temp" ( "fid" INTEGER ...
user30184's user avatar
  • 68k
12 votes
Accepted

Adding different types of geometry to layer in QGIS

If you mean adding them to a QGIS layer, the answer is 'No'. It is not possible. This is the nature of the QGIS layer. But somehow (maybe by a script) you may export layers, which have different ...
Kadir Şahbaz's user avatar

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