4

I was saving a new layer in my GeoPackage when a window showed that I was going to overwrite a file. I chose the "Overwrite File" button because it usually overwrites a single file, not the whole GeoPackage, in my experience.

How can I recover this? The whole working folder is backed up to Google Drive but the main gpkg-file was not there, only the shm and wal. The syncing was off for the whole weekend until the mishap so the main gpkg-file should be there.

0

1 Answer 1

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 update this GeoPackage correctly by using the correct option "Overwrite Layer"

overwrite layer

You were very lucky because you did not syncronize Google Drive. Otherwise you would have lost all the other tables permanently.

I am not sure how you have gathered your experience that "Overwrite File" option overwrites just one layer. Perhaps you have been working with GeoPackages which have just one layer and not noticed that the whole data file was overwritten. Or have you been thinking that individual layers are saved somehow into separate files?

I checked also the docementation of GDAL and it is a bit misleading when it comes to ogr2ogr and GeoPackage. The ogr2ogr documentation https://gdal.org/programs/ogr2ogr.html says:

-overwrite

Delete the output layer and recreate it empty

In case of GeoPackage this option will overwrite the whole GeoPackage database. Propably the same happens with SpatiaLite as well because it is a SQLite database as well.

For really overwriting just one layer in GeoPackage user must read the documentation of the GDAL GeoPackage driver https://gdal.org/drivers/vector/gpkg.html

Layer Creation Options

OVERWRITE:

If set to “YES” will delete any existing layers that have the same name as the layer being created. Default to NO

Thus the ogr2ogr syntax for overwriting an existing GeoPackage layer with new data from a shapefile is

ogr2ogr -f gpkg -update -lco overwrite=yes my_gpkg.gpkg my_table.shp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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