35

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 ...


27

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.


26

The idea you're probably thinking of is GeoPackage. Background. 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 ...


21

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.


19

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 "...


14

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 ...


13

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. [1] (ie don't use the DB Manager plugin, just use the built in '...


13

** 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 ...


13

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 ...


13

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 with fiona.open('test.gpkg', layer='layer_of_interest') as layer: for feature in layer: print(feature['geometry']) Partial output for one record ...


12

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="sf")) st_write(nc, "nc.gpkg", "nc") st_write(storms, "nc.gpkg", "storms", append = TRUE) st_layers("nc.gpkg") ## Driver: GPKG ## Available layers: ## ...


12

It's possible in QGIS3. You can click "Create Spatial index" from the Layer Properties Dialog:


12

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 ...


12

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 -...


12

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)...


11

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 ...


10

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 = QgsMapLayerRegistry.instance().mapLayers() # OR #QGIS3 lyrs = iface.layerTreeView().selectedLayers() lyrs = QgsProject.instance().mapLayers() lyrs = QgsProject.instance()...


10

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 ...


10

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 ...


9

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//vsicurl (note double slash). So to add the poly layers from: https://raw.githubusercontent.com/OSGeo/gdal/master/autotest/ogr/data/poly.zip https://raw....


9

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 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") ...


9

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 ...


8

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-...


8

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 ...


8

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 ...


8

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 ...


8

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 ...


7

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 ...


7

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.


7

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: QgsProject.instance().fileName() Since we are dealing with projects stored in databases, the file name is actually a uri. Sample uris: Project in a PostgreSQL ...


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