Monday, 30 January 2017

Rename layer in gpkg using QGIS or PyQGIS?


I have a gpkg of several layers. How can I rename them in the gpkg as well as in the QGIS layers list?


Basically, I have layer foo in my QGIS project, whose source is filename.gpkg|layername=foo. I now want to call it bar.


It's easy (rightclick, rename) to change foo to bar in the QGIS project layer list. But it's still called foo inside the gpkg. I can't rename it inside the gpkg from the GeoPackage connection inside the QGIS browser: it lets me rightclick and choose rename, but OK is greyed out (presumably since it's in use).



As a workaround, I can rename it bar in the QGIS project layer list, export it from the QGIS project layer to a temporary gpkg (where it becomes named bar and foo is forgotten), import it from there as a duplicate to the right gpkg, use the changeDataSource plugin to point the project layer to the new name, and then clean up by deleting the old foo in the gpkg. And eventually vacuum the db.


But that's a hassle given I've set up a naming convention to use across projects, and now need to rename 20+ layers across several gpkg to reflect it (and so I and others can re-use those gpkgs in other projects).




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