Thursday 19 December 2019

shapefile - Add layer to existing geopackage not working in QGIS?


My organisation uses mainly ArcGIS and we have a need to share data with contractors. I recently introduced QGIS (because one of our application uses WKT to import geospatial data and QGIS makes the conversion of various formats to WKT very easy) so I started to look at the geopackage format and QGIS as a data sharing solution - we want to stop using shapefiles because of the column length limitations.


Using QGIS I can create a geopackage with a single layer using 'save as', read and edit the layer using QGIS, read it using ArcGIS however, if I try to add layers to the geopackage using DB Manager (as per How to add another layer to GeoPackage in QGIS?) I get an 'error 11 connection to database failed'. I definitely have a connection to the geopackage in DB Manager as I can preview the existing layer and run a query (i.e. select * from [layer]).


This seems to be a bug (https://hub.qgis.org/issues/14981) that is not scheduled to be fixed so I'm wondering if there are any other tools or plug-ins available so that we can add layers to a geopackage using QGIS?


I am using Windows 10, QGIS 2.14.9 and ArcGIS 10.4.


Note: While I can add a layer to the geopackage using OGR2OGR, I cannot get 'buy-in' from our contractors, who are field specialists not IT professionals, to use command line tools instead of a GIS.


Note 2: I have discounted using spatialite for now because QGIS does not handle spatialite data created with ArcGIS. (DB Manager results in an error: dbname='H:/Temp/SQLiteTesting/BaseData/ArcSpatialite/Aspatialite.sqlite' table="arccatTrees" sql= is an invalid layer - not loaded)



Answer



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 'save as' layer function)



[1] See https://github.com/qgis/QGIS/commit/85fbc4a7d902c12794fbbfeec5ce43d8a2c0887e


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...