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 additions regarding new QGIS 2.99 alias QGIS 3, Nov. 2017 (also added in comparison): GeoPackage now works nearly without any problems in QGIS 3. Did encounter some ...
The idea you're probably thinking of is GeoPackage.
The background to the requirement came from the US Army Geospatial Center which is part of the Corps of Engineers, who were looking for a way to put maps and other information (points or interest, routes, photographs and other observations) into a simple "one file has it all" format for mobile ...
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 the field names in your GeoPackage data to lowercase in the PostgreSQL table. To maintain case you would need to use the lco option like:
ogr2ogr -f PostgreSQL "...
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 which will create an OGC GeoPackage dataset. This is essentially an SQLite database with ST_Geometry storage plus some extra OGC features.
You can use this ...
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 overwriting the whole file or instead appending the layer as a new layer within the geopackage.  (ie don't use the DB Manager plugin, just use the built in '...
** 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/ dropping tables.
You can use the DB Manager core plugin. Open DB Manager and select your GeoPackage connection from the tree on the left. Select the spanner icon ...
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 revealed to me that there is a distinction between Spatialite geometries and GeoPackage geometries.
To work with GeoPackages in Spatialite, there are several ...
You can use the gdal/ogr, fiona (built on gdal/ogr) or geopandas (built on fiona) python libraries.
Below is a fiona example:
# No need to pass "layer='etc'" if there's only one layer
with fiona.open('test.gpkg', layer='layer_of_interest') as layer:
for feature in layer:
Partial output for one record ...
You can do this using the append flag on sf::st_write():
nc <- st_read(system.file("shape/nc.shp", package="sf"))
storms <- st_read(system.file("shape/storms_xyz.shp", package="sf"))
st_write(nc, "nc.gpkg", "nc")
st_write(storms, "nc.gpkg", "storms", append = TRUE)
## Driver: GPKG
## Available layers:
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 button has an Save Style option and you can choose Save in database (GeoPackage).
The style is saved on a table inside your GeoPackage called layer_styles. The ...
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
Addition of a new subdataset to an existing GeoPackage, and choose a
non default name for the raster table.
gdal_translate -of GPKG new.tif existing.gpkg -...
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 and see in which state it is.
Some tips: QGIS stores the changes in the cache files before applying them to the geo-package. If you have the same (or a similar)...
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 of it grows as you have noticed until the database file is compressed.
Copying GeoPackage into a new GeoPackage with ogr2ogr is a good option but there is a ...
You need to use QgsVectorFileWriter.writeAsVectorFormat.
If you store one layer per GPKG file you just need:
# get layer list by one of:
lyrs = iface.mapCanvas().layers() # OR
lyrs = QgsMapLayerRegistry.instance().mapLayers() # OR
lyrs = iface.layerTreeView().selectedLayers()
lyrs = QgsProject.instance().mapLayers()
lyrs = QgsProject.instance()...
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 you want it, and at the bottom left click Style > Save as Default > Datasource Database.
Then the next time you add this geopackage layer to QGIS it will ...
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 geometry type, extent, CRS, date and so on, the second query selects the number of features. The script works on the first featuretable in a geopackage only, may ...
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//vsicurl (note double slash).
So to add the poly layers from:
Geopandas is extremely useful and easy to use for this kind of thing:
You can load vector data with attributes (e.g. from geopackages, shapefiles, etc.) into ?(geo)pandas dataframes which allow really easy analysis of the data without messing around with ogr/gdal.
import geopandas as gpd
data = gpd.read_file("path.mygeopackage.gpkg")
GeoPackage has just one file for data (.gpkg) and .wal and .shm take care of "write ahead logging" and they disappear when the database connection is closed and pending changes are written into .gpkg. What you should do is to backup your local .gpkg that contains the updated table and continue work with a copy of the .gpkg that you have in Google Drive. Then ...
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 GeoPackage. Making less but bigger transactions is faster. You can find some numbers from https://stackoverflow.com/questions/1711631/improve-insert-per-second-...
If you look at the Split vector layer tool script, you will see that .gpkg is hard-coded inside the script. This means there is no way to change the output format of the file directly from the GUI of script tool.
However, if you want the output to be shapefile not Geopakage, you need to change that inside the script. The script is called VectorSplit which ...
Those GeoPackages do have spatial indexes ready but there is a small glitch in how the GeoPackage databases are created. That can be seen by reading the contents of the gpkg_geometry_columns table
SELECT ROWID, "table_name", "column_name", "geometry_type_name", "srs_id", "z", "m" FROM "gpkg_geometry_columns" ORDER BY ROWID
As you can see, all three tables ...
The binary format for geometry in GeoPackages is not compatible with the format used in Spatialite. That's (partly) why GDAL has separate drivers.
When I start the Spatialite GUI it helpfully displays this:
And that means instead of querying the table d I can query vgpkg_d and the Spatialite geometry functions will work:
If I query from the original table ...
ArcMap should be able to open a GPKG, but you may need to follow these steps (I don't believe you can drag and drop)
Alternatively, you can export to ESRI SHP direct from QGIS, although bear in mind this has limitations on field name length (processing tools default to GPKG, but right click on a layer -> Export -> Save As/Save Features As and you ...
QGIS is made to use Write Ahead Logging (WAL) by commit https://github.com/qgis/QGIS/commit/f939e9cff598b95e95b0de099d0c9a92eed0ea9c
The new behavior should be to open gpkg database file in WAL journal mode if file is on local disk but turn it back to the default journal mode when the connection is closed.
I made a test with QGIS 2.18.2 and that seems to ...
You can load a project from a database storage (e.g., PostgreSQL or GeoPackage) in this way:
Where uri is the file name of the project, which you could get from:
Since we are dealing with projects stored in databases, the file name is actually a uri.
Project in a PostgreSQL ...