0

This seems like it ought to be straightforward:

from osgeo import gdal
gpkg = gdal.OpenEx('path_to_gpk',gdal.OF_VERBOSE_ERROR,allowed_drivers=['GPKG'])
error = gpkg.DeleteLayer(0)

After running this error is always a OGRERR_FAILURE. The geopackage has been created by QGIS so I would have thought should be standard.

Can't see any way to debug further into the GDAL calls apart from a GDB session, which I might try later.

1
1

Simple indeed....

Proper code below:

from osgeo import gdal
gpkg = gdal.OpenEx('path_to_gpk',gdal.OF_OF_UPDATE,allowed_drivers=['GPKG'])
error = gpkg.DeleteLayer(0)
# this code is also possible as an alternative
# doesn't seem to delete everything though, so possibly DeleteLayer() is better
# gpkg.ExecuteSQL('DROP TABLE [layer name]')
gpkg.ExecuteSQL('VACUUM')

Note that you will have to refresh any connections (e.g. in QGIS) manually and there is no refresh button as of 3.10.

1
  • What remains after DROP TABLE? It certainly works when it is used as -sql parameter with ogrinfo.
    – user30184
    Oct 17 '19 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.