2

How can I create new Geopackage layer with the same styling and fields, but empty of features, within same dpkg file. I have yet, houses.dpkg and within this dpk I have created houses and fences tables (layers), but now I want to create houses2 and fences2 within the same dpkg, but with same styling and table structure (fields), as the previous two tables=layers, but to be independet (not linked in any way) with their originating layers (houses and fences), except they are stored in the same dpkg file.

3

I am not sure about how to do it with QGIS but copying the table schema into a new table is easy with ogr2ogr.

ogr2ogr -f gpkg -update -append -nln houses2 -sql "select * from houses where
1=2" my_geopackage.gpkg my_geopackage.gpkg

The command will create a new table that is named with the -nln (new layer name) parameter but because 1=2 is never true then no data rows from the source table are selected.

For copying the styles you can at least use the context menu commands Styles-Copy Style/Paste Style.

As a sort of workaround you can copy the whole layer with data with the QGIS DB Manager as described here Saving duplicate geometry layers into a geopackage?. After selecting all features and deleting them you have what you want. But remember that deleting data from GeoPackagae database does not shrink the database file before you run VACUUM which is a slow operation with big databases.

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.